A href = & quot; javascript: & quot; and a href = & quot; # & quot ;,

Source: Internet
Author: User

A href = "javascript:" With a href = "#",

<a href="javascript:;"></a>    <a href="#"></a>

These two methods. What are the differences between the two statements? Which one is used to write more standards?

Connecting href = "#" means connecting to the current page is meaningless, and the page will not be refreshed. This is an anchor link.

When creating a webpage, the parameters in the html language are used to specify the url ### of the link, that is, the link to this page, and href = "Address" is the link to this page. The default page is displayed, A new window is not displayed. If # is removed when the connection is null, the mouse and hand cursor are not displayed. In general, a fake link pointing to this page can also be followed by the anchor id. This is actually another usage of bookmarks.

Syntax: <a href = "# bookmark name"> link text </a>

Bookmarks linked to different pages

Syntax: <a href = "link file address # bookmarkname"> link text </a> (note the quotation marks and)

Under normal circumstances, click the <a href = "# bookmark name"> link text </a> link, the cursor will automatically jump to the following page: <a name = "bookmarkname"> text </a>.

If we just want to write a tag without any event jump. I personally do not recommend using <a href = "#">.

However, the href attribute can also identify javascript code segments.

Javascript: a pseudo-protocol. It allows us to call javascript Functions through a link. However, because this function is empty, we call an empty function without any material changes. You can also click and run the tag. If there is a large amount of content in the page and the upper and lower scroll bars are available, using href = "#" will cause the jump to the top of the page. Use href = "javascript:;" to avoid page jumps!

Therefore, if we want to write a dead a tag, use

<a href="javascript:;"></a>

It will be more conducive to increasing the user friendliness of our pages!

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.