[Turn]href= "#" and the difference between javascript:void (0)

Source: Internet
Author: User

This article transferred from: http://www.cnblogs.com/suizhikuo/p/3928411.html

If we want to place the link in the a tag into an empty link, we will generally use two methods:

1

<a href="#"target="_blank"></a>

Or

1

<a href="javascript:void(0);"target="_blank"></a>

The above two methods many people think is the method of empty link, but the two methods are different, what is the difference? Let's talk about it today.

Href= "#" Method:

In fact, the meaning of the empty connection, but after the click will automatically jump to the top of the page, because this method is equivalent to clicking on an anchor, but this anchor is not written ID, so the default jump to the top of the page.

href= "javascript:void (0);" Method:

Void is an operator that specifies that an expression is evaluated but does not return a value. If you write 0 (void (0)) in void, nothing is done and an empty link is formed.

#与javascript: The difference between void (0):

So, #与javascript: the difference between void (0) is also obvious, #方法会跳转到页面的顶部, and there will be # after the page URL, and the Javascript:void (0) method will not, so if it is an empty connection, it is recommended that javascript: void (0).

[Turn]href= "#" and the difference between javascript:void (0)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.