是否有可能獲得觸發事件的元素.each()
?捕獲每個()內.on
$(document).on("change", ".multiple-elements", function() {
$(this).each(function() {
console.log("test");
});
});
該示例只觸發一次,但是可以觸發它的所有更改嗎?
是否有可能獲得觸發事件的元素.each()
?捕獲每個()內.on
$(document).on("change", ".multiple-elements", function() {
$(this).each(function() {
console.log("test");
});
});
該示例只觸發一次,但是可以觸發它的所有更改嗎?
$('.multiple-elements').each(function(){
$(this).on('change', function(){
console.log('test');
})
});
更改事件是在表單輸入發生更改時觸發的。我認爲那是他所指的變化事件。這是一個codepen。 http://codepen.io/matthewtoledo/pen/LNodqM?editors=1111 – mrbinky3000
因爲是,不,不是真的。
原因是更改事件將獨立觸發每個元素,一個接一個。這是正常的DOM行爲。
因此,如你所注意的那樣,這樣做並不能幫到你。
我預見的解決方案是使用去反彈函數在處理程序上重新發射事件。
您是否打算使用'input'事件? Per [this reference,](https://developer.mozilla.org/en-US/docs/Web/Events/change)'與輸入事件不同,更改事件不一定會針對元素值的每次更改觸發。 '另請參見:https://developer.mozilla.org/en-US/docs/Web/Events/input – zipzit
是的,我正在使用輸入元素 – guub