href= the difference between "#" and href= "javascript:"

Source: Internet
Author: User

The href attribute of the 1.<a> tag specifies that the value of the Url,href property of the hyperlink target can be a relative or absolute URL for any valid document, including fragment identifiers and JavaScript code snippets. href= "javascript:", where JavaScript: is a pseudo-protocol that allows us to invoke JavaScript functions via a link. And in this way javascript: can implement a-tag click event Runtime, if the page content is many, When there are scrollbars, the page does not jump and the user experience is better.

href= "javascript:" This is an empty statement in itself. Simply put, this a-tag click link is out of action

2.href= "javascript:" The main role makes it a hyperlink style, it looks like a button, there is action is not text, in fact, is linked to an empty statement, the general set onclick event.

Label in HTML means a hyperlink

1 The general role of the jump page needs to set the jump page is to set the address to jump in the href attribute

2. As a button to use, you can click but do not jump to the page but do other processing, you need to set the href attribute to javascript:



JavaScript: Indicates that this is an empty connection. No response after clicking.
It's like #, but a # Click will roll to the top after a long page, and JavaScript: there's no such thing. He is still in the current position after testing.
Of course # # #这样的效果就跟javascript: the same

href= the difference between "#" and href= "javascript:"

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.