[英]How to handle div image click event for every time execution of div
function first(Objs) {
var imgid= Objs;
secondMethod(imgid);
$('#imags_'+imgid.id).one('click', function(e) {
alert(imgid.id)
});
}
function secondmethod(imgid) {
var boxText = document.createElement("div");
boxText.id="imags_"+imgid.id;
boxText.innerHTML = '<div id="content" >' + '<img src=\"image.png\" width=\"50px\" height=\"50px\" id ="\images_id\" />' + '</div>';
}
Objs.id=1
) . 我每10秒刷新一次(执行)第一个方法( Objs.id=1
)。 Give the image a class: 给图像一个类:
boxText.innerHTML = '<div id="content" >'+
'<img src=\"image.png\" width=\"50px\" height=\"50px\" class ="\images_id\" />'+
'</div>';
And use a delegated event: 并使用委托事件:
$(document).on('click', '.images_id', function() {
alert(this.id)
});
Also, your example doesn't show it but I assume boxText
is appended to the DOM at some point? 另外,您的示例没有显示它,但是我假设boxText
在某个时候附加到了DOM?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.