& Lt; a & gt; tag href attributes and onclick events

Source: Internet
Author: User

The a tag is mainly used for page Jump. It can be implemented through the href attribute or in The onclick event.

<A onclick = "window. location. href = 'www .cnblogs.com '" href = "javascript: void (0);"> blog </a>

Blog

This code is fine in mainstream browsers, but cannot be redirected in IE6. What is the reason?

Javascript: void (0 );

Void (arg); can be understood as a function that returns null forever, but its parameter cannot be null. Its parameters can be any expressions or even functions.

<A href = "javascript: void (name = 'blog Service'); alert (name);"> test </a>

Test

IE6 first runs the events bound to the DOM, such as onclick. If the bubble is not blocked, the href attribute is executed sequentially. Void (0); does not need to execute any event, IE6 tells the browser not to execute any event (overwrite the previous action), and terminating the bubble is equivalent to return false; therefore, the browser does not perform any action. So you only need to block the bubble event in The onclick event.

<A onclick = "window. location. href = 'HTTP: // www.cnblogs.com '; return false; "href =" javascript: void (0); "> blog </a>

Blog

In this way, ie6.

Another method is to avoid using javascript: void (0) instead, in the href attribute, # originally meant the anchor # name. Therefore, when no anchor is specified, it will go to the top of the page. # It has a specific meaning. The default value is # top. If # has content that will be considered as a tag and the corresponding tag is found on the page, the page will jump to the top if it cannot be found, if you do not want to jump, you can use ##### to specify a meaningless tag.

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.