点击过多后,jQuery停止加载功能 [英] Jquery stop load function after too many clicks

查看:94
本文介绍了点击过多后,jQuery停止加载功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在链接上单击用户太多次后,如何停止加载功能?

How can I stop loading function after user is clicked too many times on link?

jQuery代码如下:

Jquery code looks like:

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

});

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

});

});

HTML:

<div class="menu_rfr prof_info" id="prof_info" rel="?a=1">info</div>
<div class="menu_clickable prof_info3" id="prof_info" rel="?a=3">info 3</div>

这是带有此Jquery代码的示例页面的链接. 链接文本

this is the link of the sample page with this Jquery code. link text

推荐答案

在单击按钮后将其禁用:

Disable the button once it has been clicked:

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

        // reactivate it after some loading has completed
        $(this).removeAttr("disabled");        
     });
});

您应始终重新激活success回调中的链接,以确保加载已完成,例如:

You should always reactivate the link within the success callback to ensure that the loading has completed, e.g.:

$.get($(this).attr('rel'), function(html) {
    $("#main").html(html);
    $(this).removeAttr("disabled");
});

根据您的评论进行了更新.如果您的操作"元素是div,则必须取消绑定click事件,以防止重新点击产生效果,并在加载完成后重新绑定,例如:

updated, based on your comment. If your 'action' element is a div, you will have to unbind the click event to prevent re-clicks from having an effect, and re-bind once the loading has completed e.g.:

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);

这篇关于点击过多后,jQuery停止加载功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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