我附加了来自 javascript 的复选框输入字段。之后,我需要捕获该复选框字段的单击事件。但我不能。我尝试了以下说明:
-An append in jquery code and click function?
-jQuery 1.9 .live() is not a function 。
这是我的代码
var htmlData='<input type="checkbox" name="is_pay[]" class="is_pay">';
$('.container').append(htmlData);
$('.is_pay').on('click', function(){
alert('hi');
});
最佳答案
因为脚本运行时该项目不存在,所以监听 .container
上的点击:
var htmlData='<input type="checkbox" name="is_pay[]" class="is_pay">';
$('.container').append(htmlData);
$(".container").on("click", ".is_pay", function() {
alert("hi");
});
关于javascript - 无法捕获由 js 附加的类的单击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55945765/