jQuery更改事件不会在Internet Explorer(IE) [英] jquery change event not firing in Internet Explorer (IE)

查看:156
本文介绍了jQuery更改事件不会在Internet Explorer(IE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定我知道还有其他问题与我相关,但没有我已经阅读回答我的问题。

Ok I know there are other questions out there related to mine, but none I've read answer my question.

我有一个选择标记有一些选项我绑定到更改事件,但当用户单击进入选择框,然后向上/向下按下更改事件不会在IE中触发。它在Firefox中触发,我没有检查Chrome。

I have a select tag with some options I bound to the change event but when a user clicks into a select box and then presses up/down the change event doesn't fire in IE. It fires in Firefox, and I haven't checked Chrome.

所以我想我想知道是否有一个简单的修复,我想只是做

So I guess I would like to know if there is an easy fix for this I would like to just do

$("#selector").change(function () {//Add code });

现在我的解决方法是这样做:

A workaround for me right now is to do this:

$("#selector").bind('change keyup',function () {//Add code });

我想我可以这样创建一个插件:

I guess I could create a plug-in like so:

$.fn.myChange = function (fcn) { return this.bind('change keyup',fcn);}

我的主要想法是jquery作为一个库应该抽象出浏览器(in)兼容性的丑陋细节,所以我宁愿如果我仍然可以使用base .change函数,而不必担心我在使用什么浏览器。

My main thought is that jquery as a library should abstract away the ugly details of browser (in)compatibility so I would prefer if I could still use the base .change function and not have to worry about what browser I'm on.

我只是想知道这是否应该这样做。有更好的方法吗?

I just wanted to know if this is the way it should be done. Is there some better way?

更新

我提交了错误到jquery小组,看看他们的想法。

I submitted a bug to the jquery team, to see what they think.

这是一个示例,显示了问题。打开它,点击进入选择框,然后向上/向下按。您会注意到IE不会触发更改事件,而FF和Chrome。

Here's an example that shows the problem. Open it up click into the select box and then press up/down. You will notice that IE does not trigger the change event while FF and Chrome does.

推荐答案

它将工作:

$("#sel").bind($.browser.msie ? 'propertychange' : 'change', function(e) {
    $("#output").append("boxval changed!" + $(this).val());
});

请注意,我添加了 + $(this).val / code>,所以你可以看到它的实际价值。

Note that I added the + $(this).val() so you could see it work on the actual value.

你可以看到它在操作中: http://jsfiddle.net/At8Ht/3/

you can see it in action here: http://jsfiddle.net/At8Ht/3/

请注意,这也可以这样做: (删除浏览器嗅探),但我没有在所有浏览器测试。

Note that this could also be done as such: (remove the browser sniff) but I have not tested in all browsers.

$("#sel").bind('propertychange change', function(e) {
    $("#output").append("boxval changed!" + $(this).val());
});

这篇关于jQuery更改事件不会在Internet Explorer(IE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆