其他分享
首页 > 其他分享> > Click event doesn't work on dynamically generated elements

Click event doesn't work on dynamically generated elements

作者:互联网

I couldn't get live or delegate to work on a div in a lightbox (tinybox).

I used setTimeout successfullly, in the following simple way:

$('#displayContact').click(function() {
    TINY.box.show({html:'<form><textarea id="contactText"></textarea><div id="contactSubmit">Submit</div></form>', close:true});
    setTimeout(setContactClick, 1000);
})

function setContactClick() {
    $('#contactSubmit').click(function() {
        alert($('#contactText').val());
    })
}

Reference : https://stackoverflow.com/questions/6658752/click-event-doesnt-work-on-dynamically-generated-elements?rq=1

 

标签:function,elements,dynamically,work,event,setContactClick,click
来源: https://www.cnblogs.com/blogkevin/p/10627231.html