我有以下代码:jQuery的onchange事件触发两次在IE8
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function()
{
$('#test').bind("change", function()
{
alert(this.value);
this.value = jQuery.trim(this.value);
});
});
</script>
<input type="text" id="test" />
<br />
<input type="radio" />
</body>
</html>
在IE8中,如果我输入任何文字,以“测试”输入,按“TAB”我会得到警告信息两次。
但是,如果我注释行 “THIS.VALUE = jQuery.trim(THIS.VALUE);”该消息将只显示一次。
为什么发生这种情况?以及如何避免两次“onchange”处理程序调用?
但在Chrome 13中,FF4 onchange事件仅触发一次。 – maxvasil
@vasmt这是跨浏览器脚本的亚! –