The problem priority level used by the href and onclick in the Html a tag

Source: Internet
Author: User

The most we can use when making a Web page is a tag hyperlink.

But sometimes you need to use both the href and the onclick attribute in A and we'll analyze it and have different effects under different browsers.

1 Order
IE 6:href Trigger after onclick first
Other browsers trigger the href after triggering Onlick first

2 href= "javascript:xxx ()"
Cannot pass in this as a parameter
OnClick can
<a href= "Javascript:alert (' href event ');" onclick= "clickevent (this);" >

3 Priority Firing method if return false causes the latter event not to be triggered
Like what
<a href= "Javascript:alert (' href event ');" onclick= "clickevent (this); return false; " >

4
<a href= "#" > will cause the page to be anchored to the bookmark location,

5
Because of the reason of 1 and 4
At the same time there are <a href= "#" and the onclick in the IE6 because the page was re-loaded because of the href, causing the onclick event to be discarded by the browser.


6 Summary:
1) When you do not need to pass this as the parameter of the method, it is recommended
Use only href= "JavaScript:"

2) If you need to use this parameter, it is recommended
<a href= "javascript:void (0)," onclick= "dosomthing (This)" > as the following column sub. We need a at the first and second click to access the href after the 3rd time to access another address

var href=0

function Clicka (obj)
{
if (href==2)
{
Obj.href= "HTTP://WWW.86P.COM/?QC";
}else
{
href++;
}
return true;

}

<a href= "http://www.fxxz.com/" Target=_blank id= "Showa" onclick= "Clicka (This)" > Open high Speed Download </a>

The problem priority level used by the href and onclick in the Html a tag

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.