This question already has answers here:
Event binding on dynamically created elements?
                                
                                    (23个答案)
                                
                        
                                4年前关闭。
            
                    
$(document).ready(function(){
    $(".click").on('click', function(){
        var target = $(this).parent().children(".expand");
        $(target).slideToggle();
    });
});


AJAX加载的HTML内容:

<div class="click" >...div with expand ....</div>
<div class="click" >...div with expand ....</div>


有人可以更正我的代码吗?提前致谢!

最佳答案

<div class="click"></div>是动态创建的元素,因此我们需要在此处使用事件委托。

参考:Event binding on dynamically created elements?

尝试这个,

$(document).on('click', '.click', function(){
    // Do something
});

关于php - jQuery无法处理ajax加载的内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29252624/

10-09 03:54