html 超链接 没有刷新
a 标签用在 Jquery 下拉菜单中,通常用在 ajax 中。但问题是 它刷新页面。我怎样才能强制它不刷新?
谢谢,
the a tag is used in Jquery dropdown menus and generally in ajax . But the problem
it refeshes the page . How can I force it not to refresh ?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在点击处理程序中使用
e.preventDefault()
并return false;
。Use
e.preventDefault()
in the click handler andreturn false;
.只需在 href 中添加
javascript:void(0)
示例:
Home
Just add
javascript:void(0)
in hrefExample:
<a href="javascript:void(0)">Home</a>
您可以为锚点上的
click
事件添加一个处理程序,该处理程序在完成其工作(执行和处理 Ajax 请求)后返回 False。这将阻止事件传播和调用默认处理程序(即GET
由href
引用的资源)。You can add a handler for the
click
event on your anchors which after doing its work (executing and processing an Ajax request) returns False. This will prevent the event from propagating and calling the default handler (which is toGET
the resource referred to byhref
).我有类似的问题,并这样做来解决。
href
属性。很多人会把它设置为“#”,因为“它不会去任何地方”。不完全正确。它会将您带到页面顶部,当您有滚动页面时,这会很痛苦。如果您希望当有人将鼠标悬停在光标上时光标发生变化,请使用 :-
光标 : 指针
设置您的 href-less a 标签的样式如果您执行这两件事,您的 a 标签将不会去任何地方,不会滚动屏幕,并且会当用户将鼠标悬停在它们上时,它们看起来就像常规链接。
I had a similar issue, and did this to resolve.
href
attribute. Many people will set it to "#" because "it doesn't go anywhere". Not entirely true. It'll take you to the top of the page, which is a pain when you have a scrolling page.If you want the cursor to change when someone mouses over it, style your href-less a tags with :-
cursor : pointer
If you do those two things, your a tags won't go anywhere, won't scroll the screen and will look like regular links when a user mouses over them.