如何在< a>时阻止页面刷新标签点击? [英] How to prevent page refresh when <a> tag clicked?
问题描述
我需要将一个参数传递到网址中,同时当我点击任何< a>
标记并且空白<$ c $时,我会阻止重新加载网页c> href 属性(< a href =>
)
I need to pass a parameter into the URL and at the same time prevent page from reloading when I click any <a>
tag with a blank href
attribute (<a href="">
)
有没有办法用JS / jQuery做到这一点?
Is there a way to do this with JS/jQuery?
我已经有了这个jQuery
I have this jQuery already
$('.list-group-item a').click(function (event) {
event.preventDefault();
});
但是当我点击< a href =inbox / 1> ;消息< / a>
(任何带有href的锚)preventDefault会阻止该值传递到网址。
But when I click <a href="inbox/1">Message</a>
(any anchor with an href) preventDefault stops that value from being passed into the url.
任何人都可以提供帮助吗?
Can anyone help?
提前致谢。
推荐答案
window.location.hash =inbox / 1
可以更新网址中的哈希值。这可以通过 preventDefault 代码来完成。
window.location.hash="inbox/1"
can update the hash value in the url. This can be done with the event preventDefault code.
这篇关于如何在< a>时阻止页面刷新标签点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!