【发布时间】:2011-08-10 09:24:18
【问题描述】:
我有以下代码:
<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”处理程序调用?
【问题讨论】:
标签: jquery internet-explorer internet-explorer-8 onchange