我遇到一个问题,我想在单击一次后禁用 anchor 单击。我有 我的 anchor 标记中设置的点击属性。下面是我的 HTML
<a style="cursor:pointer;" id="someId" onclick="Myfuntion()">Verify</a>
单击“验证”后,我将 anchor 文本更改为“正在验证...”,还有一件事是我尝试禁用此 anchor 以避免在验证逻辑之间单击。
我尝试过 event.preventdefault() 并为 anchor 添加了禁用属性。 但没有任何效果。
请帮忙!
最佳答案
如果您使用 jQuery 来完成此操作,您可以更轻松地完成此操作。
在这里,我们向链接添加一个新类,以显示它已被单击。我们在点击时检查这一点。
<a style="cursor:pointer;" id="someId">Verify</a>
$('#someId').on('click',function(){
//Check if button has class 'disabled' and then do your function.
if(! $(this).hasClass('disabled')){
$(this).addClass('disabled');
Myfuntion();
$(this).removeClass('disabled');
}
});
关于javascript - 防止一键点击后 anchor 点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31652036/