Ajax调用后jQuery函数不工作 [英] Jquery function doesn't work after Ajax call

查看:143
本文介绍了Ajax调用后jQuery函数不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能:

$(document).ready(function() {
$('.post_button, .btn_favorite').click(function() {


//Fade in the Popup
$('.login_modal_message').fadeIn(500);

// Add the mask to body
$('body').append('<div class="overlay"></div>');
$('.overlay').fadeIn(300);  
return false;
});

我的页面加载内容最喜欢的按钮,但是Ajax调用,并产生更多的新内容后,该函数不会当您单击新的内容的按钮的工作。可能是什么不对?

My page loads content with favourite buttons, but after Ajax call and generated additional new content the function doesn't work when you click new content's buttons. What could be not right?

推荐答案

那是因为你使用的是动态内容。

That is because you are using dynamic content.

您需要更改您的点击呼叫委派方法,如

You need to change your click call to a delegated method like on

$('.post_button, .btn_favorite').on('click', function() {

$("body").on( "click", ".post_button, .btn_favorite", function( event ) {

这篇关于Ajax调用后jQuery函数不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆