开发者

How to stop Jquery load function

开发者 https://www.devze.com 2022-12-30 00:10 出处:网络
The Jquery load function don\'t stop if there is multiple click on the links in the menu. The jquery code looks like:

The Jquery load function don't stop if there is multiple click on the links in the menu.

The jquery code looks like:

$(document).ready(function(){

$(".menu_rfr").unbind("click").click(fu开发者_如何学运维nction() {
$("#main").html('<img src="img/spin.gif" class="spin">');
location.replace($(this).attr('rel'));
});

function handleClick() {
$(this).unbind("click");
$("#main").html('<img src="img/spin.gif" class="spin">');
$("#main").load($(this).attr('rel'), function() {

    // reactivate it after some loading has completed
    $(this).click(handleClick);        
});         
}
$(".menu_clickable").click(handleClick);
});

You can see the sample page at link text

How can I prevent users clicks if the DIV content is not loaded completely and never ending DIV loading?


The $(this) in the handleClick isn't referring to the element.

Here's some code that is one way to fix this. I think it will work, I'm not at a computer that I can test it on though.

$(document).ready(function(){

$(".menu_rfr").click(function() {
    $("#main").html('<img src="img/spin.gif" class="spin">');
    location.replace($(this).attr('rel'));
});

function handleClick(ele) {
    $(ele).unbind("click");
    $("#main").html('<img src="img/spin.gif" class="spin">');
    $("#main").load($(this).attr('rel'), function() {
        // reactivate it after some loading has completed
        $(ele).bind('click',function(event){bindClick(event.target);});        
    });        
}

function bindClick(ele){
    $(ele).bind('click',function(event){
        handleClick(event.target);
    });
}

$(".menu_clickable").each(function(){
    bindClick($(this));
});
});
0

精彩评论

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