event.preventDefault() on first click then remove

后端 未结 5 1419
余生分开走
余生分开走 2021-02-03 13:35

I have the default anchor disabled if it has a class subnav as shown in this fiddle.

I only want this disabled for the first click then I want the normal anchor function

5条回答
  •  有刺的猬
    2021-02-03 14:09

    You can pass false to one():

    $(".subnav a").one("click", false);
    

    Passing false instead of a handler is equivalent to passing a handler that returns false, effectively stopping the event's propagation and preventing its default behavior.

    This is explained in the documentation for bind():

    In jQuery 1.4.3 you can now pass in false in place of an event handler. This will bind an event handler equivalent to: function() { return false; }.

提交回复
热议问题