这必须简单。我搜索了互联网,发现语法错误只是造成这个问题的原因,但我找不到语法错误。
This has got to be something simple. I searched the internet and only found syntax errors as the cause of this problem, but I can't find a syntax error.
这是javascript:
Here's the javascript :
<script type="text/javascript" src="localhost/acrilart/javascript/jquery-1.6.4.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ function hi(){ alert('hi'); } hi(); }); </script>HTML:
<input type="text" name="cep" value="" id="cep" class="required cep field" onChange="hi()" />在页面加载时,函数 hi 被调用为预期,但我的 onChange 事件导致Firebug错误,说明函数未定义。我真的很难过。我错了'hi'了吗?
On pageload the function hi is called as expected, but my onChange event causes a Firebug error, saying the function is not defined. I'm really stumped. Did I mispell 'hi'?
推荐答案hi 函数只是在 ready 事件处理程序内的范围内。将它移到事件处理程序之外,或处理其中的绑定(并从标记中删除内联事件处理程序属性):
The hi function is only in scope inside the ready event handler. Move it outside of the event handler, or handle the binding inside there (and remove the inline event handler attribute from the markup):
$(document).ready(function(){ function hi(){ alert('hi'); } $("#cep").on("change", hi); });更多推荐
onChange函数未定义
发布评论