Javascript 通过jQuery方法调用动态添加的html元素
在动态添加的html元素上调用JavaScript/jQuery1.9.1方法会有一些麻烦 以下是我的JS代码: 我的动态HTML代码:Javascript 通过jQuery方法调用动态添加的html元素,javascript,jquery,dynamic,listener,Javascript,Jquery,Dynamic,Listener,在动态添加的html元素上调用JavaScript/jQuery1.9.1方法会有一些麻烦 以下是我的JS代码: 我的动态HTML代码: var html=”“; 对于(var i=0;i尝试使用on(),因为live()在较新版本的jQuery中已被弃用和删除: $('#table').on('click', '.download', function() { alert(this.id); }); 适合我吗?改用.on $(document).on("click",".downl
var html=”“;
对于(var i=0;i尝试使用on()
,因为live()
在较新版本的jQuery中已被弃用和删除:
$('#table').on('click', '.download', function() {
alert(this.id);
});
适合我吗?改用.on
$(document).on("click",".download",function() {
var buttonId = $(this).attr("id");
alert(buttonId);
});
这样使用:
$(document).on("click",".download",function() {
//put your code here
});
$(document).on("click",".download",function() {
var buttonId = $(this).attr("id");
alert(buttonId);
});
$(document).on("click",".download",function() {
//put your code here
});