jQuery why this does not work $(“:input”).change(function(){});

99封情书 提交于 2019-12-13 07:08:25

问题


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

Basic idea is when input changes, do the function. But it wouldn't work with IE8, when I changed some words in the input text field, the function was not triggered. This does not happen with other versions of IE(9+) or other browsers.


回答1:


Maybe its an issue with the event itself. maybe try:

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

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

Edit Note: Newer jQuery versions take of this themselves!

And for lower IE8, if needed:

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

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


来源:https://stackoverflow.com/questions/17359952/jquery-why-this-does-not-work-input-changefunction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!