The difference between the href in the hyperlink a tag and the use of JavaScript in the onclick

Source: Internet
Author: User

The difference between the JavaScript in the onclick is generally useless to pay no attention to, but the error is somewhat depressed, read this chapter explains the following:

Had always been very casual, later see. NET LinkButton seems to be used in <a href= "Javascript:fun ();" The form of ...>, today in this way encountered some problems, pick the article and my conclusions put below:

1. The linked onclick event is executed first, followed by the action under the HREF attribute (page jump, or JavaScript pseudo-link);
2. Assuming that both the href and the onclick are present in the link, the onclick must get a return value of FALSE if you want the action under the HREF attribute to not execute. If you do not believe, you can comment out the return false in the Gogoogle function;
3. If the page has a scroll bar too long and you want to perform the action through the linked onclick event. Its href attribute should be set to Javascript:void (0), instead of #, which prevents unnecessary page jumps;
4. If a function with a return value is called in the href attribute of the link, the contents of the current page will be replaced by the return value of the function;
5. There is a difference when you hold down the SHIFT key.
6. The problem I encountered today, in the IE6.0 in the form of href access to parentnode.
7. Try not to use JavaScript: protocol as the HREF attribute of a, which will not only lead to unnecessary triggering of window.onbeforeunload events, in IE will make GIF animated pictures stop playing.
That's all, it took a lot of time on this.

Reason
When using the CheckBoxList control to implement a link after each checkbox, click the link to implement some of the functions, but also to check the checkbox.

<input type= "checkbox" Name= "Chk" id= "chk" >
<label for= "Chk" > select it <a onclick= "This.parentNode.click ();" Href= "#" style= "Border:solid 1px blue;" Links in >[label]</a></label>

Finally, we use parentnode to achieve.

[HTML]View Plaincopy
      1. <a href="javascript:void (0)" onclick="DefineField (this); return false">clicktodefine </a>

The href of the hyperlink a label differs from the use of JavaScript in the onclick

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.