jQuery为什么这不起作用$(“:input”)。change(function(){});

时间:2013-06-28 07:58:49

标签: javascript jquery html css internet-explorer-8

$(":input").change(function() {alert("hello");}

基本思路是当输入改变时,做功能。但它不适用于IE8,当我在输入文本字段中更改了某些单词时,该功能未被触发。其他版本的IE(9+)或其他浏览器不会发生这种情况。

1 个答案:

答案 0 :(得分:2)

也许这是事件本身的问题。也许试试:

var ie8 = /msie 8/gi.test(window.navigator.userAgent);

$("input").bind(ie8 ? 'propertychange' : 'change', function() {
   alert("hello");
}

修改 注意:较新的jQuery版本会自行处理!

对于较低的IE8,如果需要:

var lowIE = / msie(6 | 7 | 8)/gi.test(window.navigator.userAgent);

$("input").bind(lowIE ? 'propertychange' : 'change', function() {
   alert("hello");
}
相关问题