The difference between the href and the onclick in a tag is "turn"

Source: Internet
Author: User

The difference between the href and the onclick JavaScript is generally useless to the attention, 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 Netizen's article and my conclusions placed below:

      1. linked   onclick   event is executed first, followed by   href   Properties Action (page jump, or JavaScript
      2. If   is present in the link, href   and   onclick , if you want to   href The action under the   property does not execute, onclick   must get a   false   return value. Do not believe, you can   gogoogle   function   return false   comment out;
      3. if the page is too long with scroll bars, And you want to perform the action through the linked   onclick   event. It should be   href   property set to   javascript:void (0); , not   # , This prevents unnecessary page jumps;
      4. if a function with a return value is called in the linked   href   property, 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, IE6.0 in the form of href access to parentnode.
      7. Try not to use JavaScript: protocol as the HREF attribute of a, which not only leads to unnecessary triggering of window.onbeforeunload events, but also makes GIF animated pictures stop playing in IE.

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.