Answers:
您应该为on函数提供选择器:
$(document).on('change', 'input', function() {
// Does some stuff and logs the event to the console
});
在这种情况下,它将按预期工作。另外,最好指定一些元素而不是文档。
阅读这篇文章可以更好地理解:http : //elijahmanor.com/differences-between-jquery-bind-vs-live-vs-delegate-vs-on/
$(document).on({ change: handleChange }, 'input');加上函数const handleChange = (event) => { $(event.target)...避免麻烦就很好了this。
您可以采用任何一种方法:
$("#Input_Id").change(function(){ // 1st
// do your code here
// When your element is already rendered
});
$("#Input_Id").on('change', function(){ // 2nd (A)
// do your code here
// It will specifically called on change of your element
});
$("body").on('change', '#Input_Id', function(){ // 2nd (B)
// do your code here
// It will filter the element "Input_Id" from the "body" and apply "onChange effect" on it
});
$("#id").change(function(){
//does some stuff;
});
$(document).on('change', '#id', aFunc);
function aFunc() {
// code here...
}
您可以使用:
$('body').ready(function(){
$(document).on('change', '#elemID', function(){
// do something
});
});
它和我一起工作。