This question already has answers here:
Event binding on dynamically created elements?
                                
                                    (23个答案)
                                
                        
                                5年前关闭。
            
                    
嗨,我无法在我的代码上触发简单的事件委托,所选DIV中的dom要素是动态创建的。

<div class="holder" style="-moz-user-select: none;">
  <a class="jp-previous page1"> previous</a>
  <a class="page">1</a>
  <span class="jp-hidden">...</span>
  <a class="page jp-current">2</a>
  <a class="jp-next page1 jp-disabled">next </a>
</div>


以下是我在ready块中执行的JS代码。

jQuery("div[class=holder]").on('click',function() {
        alert('i am here');
    });

最佳答案

尝试这个....

jQuery(document).on('click','div[class=holder]',function() {
        alert('i am here');
    });


也可以使用

 jQuery(document).on('click','.holder',function() {
            alert('i am here');
        });

07-24 17:06