Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[html] 第235天 请解释下href="javascript:void(0)"和href="#"的区别是什么? #1612

Open
haizhilin2013 opened this issue Dec 6, 2019 · 2 comments
Labels
html html

Comments

@haizhilin2013
Copy link
Collaborator

第235天 请解释下href="javascript:void(0)"和href="#"的区别是什么?

#588

我也要出题

@haizhilin2013 haizhilin2013 added the html html label Dec 6, 2019
@cxwht
Copy link

cxwht commented Dec 6, 2019

一个是执行函数,一个是跳转链接,执行函数的可以return一个false 使跳转或者其他事件被阻止

@zhaofeipeter
Copy link

zhaofeipeter commented Jul 29, 2020

"#" 包含了一个位置信息,默认的锚是#top 也就是网页的上端。
而javascript:void(0), 仅仅表示一个死链接。
在页面很长的时候会使用 # 来定位页面的具体位置,格式为:# + id。
如果你要定义一个死链接请使用 javascript:void(0) 。
实例
<a href="javascript:void(0);">点我没有反应的!</a>
<a href="#pos">点我定位到指定位置!</a>
<br>
...
<br>
<p id="pos">尾部定位点</p>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
html html
Projects
None yet
Development

No branches or pull requests

3 participants