简体   繁体   English

jQuery load()之后,jQuery单击处理程序不起作用

[英]After jQuery load(), jQuery click handler doesn't work

I have written a click function on the HTML page for DIV elements. 我在HTML页面上为DIV元素编写了一个click函数。 But after using jQuery load(), that click function for the DIV elements does not work. 但是在使用jQuery load()之后,DIV元素的单击功能不起作用。 For example: 例如:

$(".about .visible").click(function () {
$("form").toggleSlide();
});
<div class="mypro"> 
<div class="about">
<div class="visible"></div>
here is my text
</div>
</div>

If I use: 如果我使用:

$(".mypro").load("get.php");

Actually this is the original code: 实际上,这是原始代码:

$('.cv-right .cv-right-content .about').on({
mouseenter: function (a) {
     $(this).find('.about .visible').show();
},
mouseleave: function (a) {
    $(this).find('.about .visible').hide();
}

});

Then, jQuery code for .about .visible click will not work. 然后, .about .visible click的jQuery代码将不起作用。 How can I solve this problem? 我怎么解决这个问题?

You should delegate event to handle dynamic elements: 您应该委托事件来处理动态元素:

$(".mypro").on("click", ".about .visible", function () {
    $("form").toggleSlide();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM