Disabling links to stop double-clicks in JQuery

前端 未结 16 790
别跟我提以往
别跟我提以往 2020-12-02 11:13

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 the

16条回答
  •  忘掉有多难
    2020-12-02 12:04

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

    Does it. First line binds to all a-element with class button a function which sets (btw invalid for a-elements) disabled attribute to disabled.

    Second function uses jQuery live event rebinding to bind "disabling" function to all future instances of a-elements which have and attribute disabled

    Check jQuery Event documentation for more in-depth info on the two used functions if you want

提交回复
热议问题