我们可以禁用a
标签并在添加类后启用它吗?
像这样的东西:
$('a').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
$(this).addClass('ajax-link').attr('rel', '#content')
$(this).animate({
'top': '100px',
})
// want to re-enable it and do the normal behaviour
$(this).trigger('click')
return true
})
最佳答案
你可以这样做:
$('a').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
$(this).addClass('ajax-link')
window.location.href = $(this).attr('href')
})
.ajax-link {
color: green;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<a href="https://google.com">Test</a>
您基本上可以防止 anchor 的默认操作,这样点击就不起作用,然后添加类并手动将用户发送到链接。
我确信还有很多其他方法可以完成您的要求,这只是其中一种简单且直观的方法。
关于javascript - 单击时禁用和启用标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54251800/