jQuery 1.4.1 中的实时更改处理程序仍然不适用于 IE 中的选择元素

发布于 2024-08-19 13:04:48 字数 1099 浏览 2 评论 0原文

这个问题与我的 最后一篇是关于 jQuery 1.4 的。他们据称修复了导致更改处理程序无法在 IE 中工作的错误,但尚未完全修复。

我正在尝试将实时更改处理程序绑定到选择元素。大多数时候,当我更改它时,事件处理程序会触发。但是,如果我在页面加载后立即按 Tab 键切换到该元素,然后尝试使用键盘更改值,然后按 Tab 键离开该元素,则该事件不会在 IE 中触发。仅当我第一次尝试更改该值时才会发生这种情况。我在 IE 6、7 和 8 中注意到了这一点。在我尝试过的任何其他浏览器中都没有发生这种情况。我确信这是 jQuery 中的一个错误。有谁知道解决这个问题的简单方法?

这是一个演示该错误的示例页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<title>jQuery live change handler test 2</title>
</head>
<body>
<script type="text/javascript" src="jquery-1.4.1.min.js"></script>
<select id="test">
    <option value="a">a
    <option value="b">b
</select>
<script type="text/javascript">
$("#test").live("change", function() {
    alert('hi');
});
</script>
</body></html>

This question is related to my last one about jQuery 1.4. They supposedly fixed the bug causing the change handlers not to work in IE, but it is not fully fixed.

I am trying to bind a live change handler to a select element. Most of the time, when I change it, the event handler fires. But if I tab to the element immediately after the page loads, then try to change the value using the keyboard, then tab away from it, the event doesn't fire in IE. This only happens the first time I try to change the value. I noticed this in IE 6, 7, and 8. It does not happen in any other browsers I tried. I am sure it is a bug in jQuery. Does anyone know a simple way around this?

Here is an example page to demonstrate the bug:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<title>jQuery live change handler test 2</title>
</head>
<body>
<script type="text/javascript" src="jquery-1.4.1.min.js"></script>
<select id="test">
    <option value="a">a
    <option value="b">b
</select>
<script type="text/javascript">
$("#test").live("change", function() {
    alert('hi');
});
</script>
</body></html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文