健全性检查:第一次使用键盘时未触发更改事件
我对此进行了大量研究,并发现了一堆报告的问题和解决方案,但普遍的共识似乎是 IE6 中的所有更改问题都已在 jQuery 1.4.2 中修复。
我遇到一个问题,更改事件在 jQuery 1.4.2 中未触发,但在 jQuery 1.3.2 中成功触发。这是在IE6中。
我正要为此提交一个错误,但为了我的理智,我想先将其发布在这里,看看是否有一些我错过的愚蠢的东西。我不明白为什么会这样......
<HTML>
<HEAD>
<TITLE>jQuery 1.4.2 Problem </TITLE>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script>
$(document).ready( function() {
$("#firstBox").change(function() {
alert("CHANGE");
});
// ONLOAD of document autofocus into the first element...
$("form").find(":input:visible:first").focus()
});
</script>
</HEAD>
<BODY>
<form>
<select id="firstBox">
<option value="" selected="selected">--</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<br><br>
<input size="10" id="secondBox">
</form>
</BODY>
</HTML>
很简单,对吧?页面加载时,给予第一个元素焦点。当第一个元素发生变化时,警报。
如果您使用鼠标,它会按预期工作。页面加载,焦点位于下拉列表中,您更改选项,您会收到警报。
问题是如果你使用键盘。页面加载,焦点位于下拉列表中,您按向下箭头。选项发生变化。离开场地,没有警报。诡异的。更奇怪的是,如果您按 Tab 键返回字段并再次更改它(全部使用键盘),则这次 Tab 键退出后会触发更改事件。
有什么想法吗?
I've done a good amount of research on this and found a bunch of reported problems and solutions but the general consensus seems that all change problems in IE6 were fixed in jQuery 1.4.2.
I'm having an issue where a change event is not firing in jQuery 1.4.2, but it did fire successfully in jQuery 1.3.2. This is in IE6.
I'm about to submit a bug for this, but for my sanity I wanted to post it here first to see if there's something dumb I'm missing. I don't understand why this is working this way...
<HTML>
<HEAD>
<TITLE>jQuery 1.4.2 Problem </TITLE>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script>
$(document).ready( function() {
$("#firstBox").change(function() {
alert("CHANGE");
});
// ONLOAD of document autofocus into the first element...
$("form").find(":input:visible:first").focus()
});
</script>
</HEAD>
<BODY>
<form>
<select id="firstBox">
<option value="" selected="selected">--</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<br><br>
<input size="10" id="secondBox">
</form>
</BODY>
</HTML>
Simple enough, right? Onload of the page, give the first element focus. Onchange of the first element, alert.
If you use the mouse, it works as expected. The page loads, the focus is in the drop down, you change the option, you get the alert.
The problem is if you use the keyboard. The page loads, the focus is in the drop down, you press the down arrow. The option changes. Tab off the field, no alert. Weird. To make it even weirder, if you tab back into the field and change it again (all using the keyboard), the change event DOES fire after tab out this time.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我决定应用此修复程序并且它有效:
原因是我们的应用程序已经使用 IE6 一段时间了,并且用户习惯于选择立即触发更改的框(字段被隐藏/显示)。这样就实现了这一点。
感谢您的建议
I decided to apply this fix and it works:
Reason is our app has been using IE6 for a while and the users are used to select boxes firing changes (fields are hidden/shown) immediately. This accomplishes that.
Thanks for the suggestions
我遇到了一个问题,在我第二次更改输入的值之前,以下代码无法正常工作。
我不确定为什么,但我认为其他一些代码(.Net MVC2 客户端验证脚本)正在干扰并停止事件链。
我决定测试普通的旧式 JavaScript,它可以工作!
我不喜欢混合 jQuery 代码和纯 javascript,但这是我让它工作的唯一方法。
希望它对其他人有帮助!
I had a problem where the following code is not working until I change the value of the input a second time.
I'm not sure why but I think some other code (.Net MVC2 client validation scripts) is interfering and stopping the chain of events.
I decided to test plain old javascript and it works!
I don't like to mix jQuery code and pure javascript but this is the only way I'm getting it to work.
Hope it helps someone else!
请参考以下帖子
http://bugs.jquery.com/ticket/8083
http://msdn.microsoft.com/en-我们/library/aa158563(v=office.10).aspx
Please Refer to the following posts
http://bugs.jquery.com/ticket/8083
http://msdn.microsoft.com/en-us/library/aa158563(v=office.10).aspx
我的表单上有数百个字段,并且
onchange
不是第一次触发。我根据 MACCA1 的回复做了以下锻炼:
I had hundreds of fields on my form and
onchange
was not firing first time.I did following workout based on MACCA1's reply: