onChange函数未定义

编程入门 行业动态 更新时间:2024-10-22 09:42:29
本文介绍了onChange函数未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这必须简单。我搜索了互联网,发现语法错误只是造成这个问题的原因,但我找不到语法错误。

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函数未定义

本文发布于:2023-11-28 06:56:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641373.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   未定义   onChange

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!