簡體   English   中英

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

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

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

基本思路是輸入改變時,做功能。 但它不適用於IE8,當我在輸入文本字段中更改了某些單詞時,該功能未被觸發。 其他版本的IE(9+)或其他瀏覽器不會發生這種情況。

也許這是事件本身的問題。 也許試試:

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");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM