如何使用jQuery停止默认链接点击行为 [英] How to stop default link click behavior with jQuery
本文介绍了如何使用jQuery停止默认链接点击行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网页上有一个链接。当用户单击它时,页面上的小部件应该更新。但是,我正在做某些事情,因为默认功能(导航到不同的页面)发生在事件触发之前。
I have a link on a webpage. When a user clicks it, a widget on the page should update. However, I am doing something, because the default functionality (navigating to a different page) occurs before the event fires.
这是链接的样子:
<a href="store/cart/" class="update-cart">Update Cart</a>
这是jQuery的样子:
This is what the jQuery looks like:
$('.update-cart').click(function(e) {
e.stopPropagation();
updateCartWidget();
});
有什么问题?
推荐答案
e.preventDefault();
from https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault
取消事件,如果可以取消,
不停止进一步传播
的事件。
Cancels the event if it is cancelable, without stopping further propagation of the event.
这篇关于如何使用jQuery停止默认链接点击行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文