Href onclick event with a difference of a label Comments

Onclick javascript difference in general did not pay attention to useless, but some mistakes when depressed, see chapter explains the following text:

Had previously been very casual, the look in the linkbutton .net seems to be used in the form <a href="javascript:fun();"...> today in this way will encounter some problems, users pick the article and my conclusion on the following:

1. link onclick event is performed first , followed by a href action under the attribute (page jumps, or javascript pseudo-links);
2. Assuming there is a link in href and onclick Meanwhile, if you want action under the href attribute is not performed, onclick must get a return value of false ;
3. If the page is too long scroll bar, and you want to perform the operation by onclick event of the link. It should be href attribute is set to javascript: void (0) ;, # If not, it can prevent unnecessary page beating ;
4. If you call the link href attribute in a function return value, the current page content will be replaced by the return value of this function ;
5. in the case of holding the Shift key will be different.
6. Today my problems in accessing less than parentNode IE6.0 in the form of href.
7. Try not to use javascript: protocol as the href attribute <a>, so will not only lead to unnecessary window.onbeforeunload triggering event, and even make animated gif images to stop playing in IE.
These, spent a lot of time on it.

[Reason]
want to achieve together with links after each checkbox when using CheckBoxList control functions, links point to achieve some functions, but also the checkbox is selected.

<input type="checkbox" name="chk" id="chk">
<label for="chk">选中它<a οnclick="this.parentNode.click();" href="#" style="border:solid 1px blue;">[label中的链接]</a></label>

Finally parentNode to achieve.

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

 

Published 35 original articles · won praise 2 · Views 1372

Guess you like

Origin blog.csdn.net/weixin_41001497/article/details/104035179