A label href attribute and the onclick event usages

Source: Internet
Author: User

A label is mainly used to achieve page jump, can be achieved through the HREF attribute, can also be implemented in the OnClick event.

The code is as follows:
<a onclick= "window.location.href= ' www.jb51.net '" href= "javascript:void (0);" > Triple </a>


This code in the mainstream browser is no problem, but under the IE6 will be unable to jump the problem. What is the reason for this?

The code is as follows:
Javascript:void (0);


void (ARG), which can be interpreted as a function that returns null forever, but whose arguments cannot be null. Its arguments can be any expression or even a function.

The code is as follows:
<a href= "Javascript:void" (name = ' Triple '); alert (name); " > Testing </a>


Test

IE6 first runs the events that the DOM itself binds, such as onclick; if bubbling is not blocked, the href attribute is executed sequentially. and void (0); It is not necessary to perform any event, then IE6 tells the browser not to perform any event (overwriting the previous action), and terminating bubbling is equivalent to return false, so the browser does not perform any action. So just block the bubbling event within the onclick event.

The code is as follows:
<a onclick= "window.location.href= ' http://www.jb51.net '; return false;" href= "javascript:void (0);" > Triple </a>


This will work properly under the IE6.

Another method is to not use Javascript:void (0), and to use # can also be avoided, the href attribute of the # inherently means the anchor point #name so that when no anchor point is assigned to the top of the page. #是有特定意义的, the default is #top, if the # after the content will be considered a label and from the page to find the corresponding label jump to the place, can not find to jump to the top of the page, if you do not want to jump, you may use the ###,## #就是一个无意义的标签指定.

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.