问题描述
如果它具有class subnav,则我禁用了默认锚,如此小提琴所示./p>
我只希望第一次单击时禁用此功能,然后希望恢复正常的锚点功能.做这个的最好方式是什么?我尝试了涉及以下代码的操作,但这似乎不起作用?
$(this).unbind(event.preventDefault());
也许是这样的伪代码?
if (click count === 0 ) {
event.preventDefault();
}
还是有更好的方法来解决这个问题?
您可以将false
传递给 one() :
$(".subnav a").one("click", false);
传递false
而不是处理程序等同于传递返回false
的处理程序,从而有效地阻止了事件的传播并防止了其默认行为.
bind()的文档中对此进行了解释:
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 functionality to be brought back. What is the best way to do this? I tried something involving the below code but this didn't seem to work?
$(this).unbind(event.preventDefault());
maybe something like this psuedo code?
if (click count === 0 ) {
event.preventDefault();
}
or is there a better way to approach this?
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():
这篇关于首先单击event.preventDefault(),然后将其删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!