Home Web Front-end HTML Tutorial Analysis of the difference between a tag href=# and href=javascript:void(0) in html

Analysis of the difference between a tag href=# and href=javascript:void(0) in html

Jul 27, 2017 pm 01:36 PM
href html javascript

Let’s briefly talk about the difference between href=# and href=javascript:void(0). Friends who need it can refer to it

#"contains a location information

The default anchor point is #top is the top of the webpage

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 it jumps to the top of the page

This is not the case with javascript:void(0)

So it is best to use void(0)

or

# when calling the script ##

Wait

Several ways to open a new window link

1.window.open('url')

2.Use a 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=""
Copy after login

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

If it is a #, there will be a jump To reach the top situation, several solutions from personal collection:


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中不能显示)
Copy after login

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

Use JavaScript with caution:void(0)

void is an operator in JavaScript, which specifies that an expression should be calculated but does not return a value.

void operator. The usage format is as follows:

1. javascript:void (expression)
2. javascript:void expression
Copy after login

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 using the void operation. specifies a hyperlink. The expression will be evaluated but nothing will be loaded into the current document. The code below creates a hyperlink and nothing will happen when the user clicks the link. void(0 ) is calculated as 0, but has no effect on JavaScript


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

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 . The sentence will perform a submit operation. So under what circumstances is 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 when using void(0) ), it’s best to think about whether this page needs to be refreshed as a whole.

The above is the detailed content of Analysis of the difference between a tag href=# and href=javascript:void(0) in html. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles