Home  >  Article  >  Web Front-end  >  Summarize the differences between href=javascript:void(0) and href=#

Summarize the differences between href=javascript:void(0) and href=#

零下一度
零下一度Original
2017-05-17 16:02:091300browse

What are the differences between href=# and href=javascript:void(0)? The following is my summary of the difference between href=javascript:void(0) and href=#.

#"Contains a location information

The default anchor point 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 like this

So When calling the script, it is best to use void(0)

or 25a342f2303cd58b30ca96ee5974cf6a

56ea8152226b1444ce0c2c61f8d5d4f7wait

to open a new Several ways to link windows

1.window.open('url')

2.Use custom function

<script>        function openWin(tag,obj)        {            obj.target="_blank";            obj.href = "Web/Substation/Substation.aspx?stationno="+tag;            obj.click();        }        </script>
<a  href="javascript:void(0)" onclick="openWin(3,this)">LINK_TEST</a>
window.location.href=""

--- -------------------------------------------------- --------------------------

If it is a #, it will jump to the top. Several personal favorites Solution:

1:<a href="####"></a>
2:<a href="javascript:void(0)"></a>
3:<a href="javascript:void(
null
)"></a>
4:<a href="#" onclick="
return
 false"></a>
5:<span style="cursor:hand"></span>(好像在FF中不能显示)

------------------------------------- ------------------------------------------

Use with caution JavaScript:void(0)

void in JavaScript is a operator, which specifies to evaluate an expressionbut does not return a value
void. The operator usage format is as follows:

1. javascript:void (expression)
2. javascript:void expression

expression is a JavaScript standard expression to be evaluated. The parentheses outside the expression are optional, but it is a good habit to write them. The void operator specifies a hyperlink. The expression is evaluated but nothing is loaded into the current document. The code above creates a hyperlink and nothing happens when the user clicks the link. (0) is calculated as 0, but has no effect on JavaScript

<a href="javascript:void(0)">单击此处什么也不会发生</a>

That is to say, if you want to perform some processing without refreshing the page as a whole, you can use void(0). , but when you need to refresh the page, you need to be careful.

In fact, we can use 870cd383f150d4ad83c7c7790d241cd0 , this sentence will perform a submit operation. So under what circumstances are void(0) used more often? Without refresh, of course it is Ajax. If you look at the Ajax web page, you will generally see a lot of void(0). ,:), so before using void(0), it is best to think about whether the page needs to be refreshed as a whole.

【Related Recommendations】

1. Special Recommendation:"php Programmer Toolbox" V0.1 version Download

2. Solution to the invalid method of javascript:void(0) under ie6

3. Javascript Definition and detailed explanation of operator void(0)

4. Use javascript:void(0) with caution, why is it not good to write like this

The above is the detailed content of Summarize the differences between href=javascript:void(0) and href=#. 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