The differences between the href and onclick events of a tag are described in detail.

Source: Internet
Author: User

The differences between the href and onclick events of a tag are described in detail.

The differences between javascript in onclick are generally not noticed, but it is a little depressing when an error occurs. See the text chapter to explain it as follows:

I used to be casual. Later, let's take a look. the linkbutton in net seems to be used in <a href = "javascript: fun ();"...> in this way, I encountered some problems today. I picked some articles from netizens and put my conclusions below:

1. The onclick event of the link is executed first, followed by the action under the href attribute (page Jump, or javascript pseudo link );
2. Assume that both href and onclick exist in the link. If you want to disable the action under the href attribute, onclick must return a false value. Do not believe it. You can comment out return false in the goGoogle function;
3. If the page is too long with a scroll bar and you want to perform operations through the onclick event of the link. Set its href attribute to javascript: void (0); instead of #, which can prevent unnecessary page beats;
4. If a function with a returned value is called in the href attribute of the link, the content on the current page will be replaced by the returned value of this function;
5. The Shift key is different.
6. My problem today is that parentNode cannot be accessed in the form of href in IE6.0.
7. Try not to use javascript: As the href attribute of A. This will not only trigger the window. onbeforeunload event unnecessary, but also stop playing GIF animated images in IE.
In this case, it took a lot of time.

[Reason]
When using the CheckBoxList control, you want to add a link after each checkbox. In addition to some functions, you also need to select 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; "> [link in label] </a> </label>

Finally, it is implemented using parentNode.

<A href = "javascript: void (0)" onclick = "defineField (this); return false"> ClickToDefine </a>

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.