Home >Web Front-end >HTML Tutorial >Detailed introduction to the difference between html hollow links href='#' and href='javascript:void(0)'

Detailed introduction to the difference between html hollow links href='#' and href='javascript:void(0)'

黄舟
黄舟Original
2017-05-27 14:43:251869browse

#Contains a location information
The default anchor is #top, which is the top of the web page
And javascript:void(0) only represents a dead link
This is why sometimes the page is very long and the browsing link is obviously #but jumps to the top of the page
But javascript:void(0) is not the case
So it is best to use void(0) when calling the script
You can use the following example to test it:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title></title> 
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
</head> 
<body> 
这里是页首..... 
<p>1 
</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<p> 
1</p> 
<a href="#">这是会跳到页首的</a>
<a href="javascript:void(0)">这个不会跳动</a> 
</body> 
</html>

The above is the detailed content of Detailed introduction to the difference between html hollow links href='#' and href='javascript:void(0)'. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn