Home > Article > Web Front-end > The difference between html empty link href="#" and href="javascript:void(0)"
Note that it is the difference between jumping to the top of the page. It is better to use void(0) for better user experience.
#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. The browsing link is obviously # but it 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. Test it:
Code
<!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> </head> <body> 这里是页首..... <p> </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>
Tips: You can modify part of the code before running
# #
The above is the detailed content of The difference between html empty link href="#" and href="javascript:void(0)". For more information, please follow other related articles on the PHP Chinese website!