jQuery onclick上的ID不适用于从Ajax请求返回的ID [英] Jquery onclick on ids not working for the ids returning from the ajax request

查看:112
本文介绍了jQuery onclick上的ID不适用于从Ajax请求返回的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有用于图像悬停的document.ready功能.

I have document.ready function for image hover.

当文档中有图像ID sign_up_close时,悬停功能正在起作用.如果相同的ID来自AJAX请求,则该悬停在JQuery中不起作用.

When the image id sign_up_close is there in the document the hover is working. If the same id is coming from the AJAX request then the hover is not working in JQuery.

请给出一个解决方案,我有很多这样的功能可用于AJAX请求. AJAX请求与ID为sign_up_close的图像一同出现.

Please give a solution, I have so many functions like this to be worked on AJAX request. The AJAX request is coming with the image with the id sign_up_close.

$(document).ready(function(){
    $("img#sign_up_close").hover(function(){
        $("img#sign_up_close").attr("src","images/buttons/btn_type1_23_close_pp_icon_.gif");
    },function(){
        $("img#sign_up_close").attr("src","images/buttons/btn_type1_23_close_pp_icon.gif");
    });
});

推荐答案

如果Paolo Bergantino是正确的,另一个可行的选择是使用Jquery的LiveQuery.

If Paolo Bergantino is correct, another viable alternative is to use Jquery's LiveQuery.

可以在 http://docs.jquery.com/Plugins/livequery

您的代码可能看起来像这样:

Your code would probably look something like this:

$(document).ready(function(){
        $("img#sign_up_close").livequery(function() {
            $(this).hover(function() {
                $("img#sign_up_close").attr("src","images/buttons/btn_type1_23_close_pp_icon_.gif");
            }, function() { 
                $("img#sign_up_close").attr("src","images/buttons/btn_type1_23_close_pp_icon.gif");
            });
        });
});

这篇关于jQuery onclick上的ID不适用于从Ajax请求返回的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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