📌  相关文章
📜  javascript 事件绑定动态元素 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:28.794000             🧑  作者: Mango

代码示例1
// bind click handler to element that is added later/dynamically
document.addEventListener('click', function(e){
    if(e.target && e.target.id== 'myDynamicallyAddedElementID'){
         //do something
    }
});

//Alternatively, if your using jQuery:
$(document).on('click','#myDynamicallyAddedElementID',function(){
    //do something
});