The difference between JavaScript in onclick is usually not useful and not noticed, but it is a little depressed when something goes wrong. The explanation is as follows:
I used to be very casual, but later I saw that the linkbutton in .net seemed to be used in the form of <a href="javascript:fun();"...>. Today, I encountered some problems using this method. I will take the articles of netizens and my conclusions below:
1. The linked onclick event is executed first, followed by the actions under the href attribute (page jump, or javascript pseudo-link);
2. Assuming that there are both href and onclick in the link, if you want the actions under the href attribute not to be executed, onclick must get a return value of false. If you don't believe it, you can comment out the return false in the goGoogle function;
3. If the page is too long and there are scroll bars and you want to perform operations 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 linked href attribute, the content of the current page will be replaced by the return value of this function;
5. There will be some difference when holding down the Shift key.
6. The problem I encountered today is that parentNode cannot be accessed in IE6.0 in the form of href.
7. Try not to use the javascript: protocol as A's href attribute, which will not only cause unnecessary triggering of the window.onbeforeunload event, but will also stop playing gif animation images in IE.
That's all, I spent a lot of time on it.
[reason]
When using CheckBoxList control, you want to implement the function of linking each checkbox. In addition to clicking on the link to achieve 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>