开发者

jQuery live click fires more than once

开发者 https://www.devze.com 2023-02-21 20:04 出处:网络
I have this code for ajax a page on search click: $.ajax({ url: \"ClientsList.asp\", type: \"POST\", data: \"name=\" + Name + \"&org=\" + Org + \"&job=\" + Job + \"&type=\" + Type,

I have this code for ajax a page on search click:

$.ajax({
    url: "ClientsList.asp",
    type: "POST",
    data: "name=" + Name + "&org=" + Org + "&job=" + Job + "&type=" + Type,
    success: function(msg){
        $("#SRP").html(msg);
        $("#Loading").fadeOut("noraml",function(){
            $("#SRP").fadeIn();
        });

    }
});

then in the content loaded I have checkboxes that I need to catch, so I do that with this code

$(".SearchResultSelectBox").live("click", function(event) {
    $(this).is(":checked") ? DoCheckSelect($(this).attr("rel")) : unDoCheckSelect($(this).attr("rel"));
});

The first time I search and get the resulted page from the ajax the checkbox work great. the second time I use the search, every live click I have is doubled. the third time I use the ajax, every live click is tripled and so on...

I tried "return false" but then it work but the checkbox doesn't get 开发者_JS百科clicked

What can be done?

NEVER MIND! I had a mistake, I had the second set of function inside of the first one so every time I made the search function I made the inside function for live click again


may be try to use

unbind('click');

and bind it again for each ajax request


Try

event.stopPropagation();

$(".SearchResultSelectBox").live("click", function(event) {
    $(this).is(":checked") ? DoCheckSelect($(this).attr("rel")) : unDoCheckSelect($(this).attr("rel"));
    event.stopPropagation();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消