禁用链接以停止在JQuery中双击 [英] Disabling links to stop double-clicks in JQuery

查看:119
本文介绍了禁用链接以停止在JQuery中双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果点击一次后,如何禁用按钮类的所有链接?我希望能够在一个地方做到这一点,而不必单独更改所有这些......任何想法?

How would I disable all links with the button class after they are clicked once? I'd like to be able to do this in one place, and not have to change all of them individually.. any ideas?

到目前为止,我得到了这个:

So far I got this:

$("a.button").click(function() { $(this).attr("disabled", "disabled"); });
$("a[disabled]").click(function() { return false; });

但是第二个事件没有解雇..

but the second event isn't firing..

推荐答案

这就是我要尝试的:

$("a.button").one("click", function() {
    $(this).click(function () { return false; });
});

将所有链接与按钮类绑定。只运行一次匿名函数(因此为one),重新绑定链接返回false。

Bind all the links with class "button". Run the anonymous function only once (hence "one"), which rebinds the link to return false.

如果你想让它看起来更像你拥有的那样,试试这个:

If you want to keep it looking more like what you have, try this:

$("a.button").click(function() { $(this).attr("disabled", "disabled"); });
$(document).click(function(evt) {
     if ($(evt.target).is("a[disabled]"))
          return false;
});

这篇关于禁用链接以停止在JQuery中双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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