The onclick event of the link is executed first, followed by the action under the href attribute. Assume that both href and onclick exist in the link. If you want the action under the href attribute not to be executed, onclick must get a false return value
When using , some problems occurred, which confused me for more than a month. Now I have obtained the following conclusions from netizens, which made me suddenly enlightened and the problem was solved.
The onclick event of the link is executed first, followed by the action under the href attribute (page jump, or javascript pseudo link);
Assume that there are both href and onclick in the link, if you want the href attribute to be The action is not executed, onclick must get a false return value;
If the page is too long and has a scroll bar, and you want to perform the operation through the link's onclick event. Its href attribute should be set to javascript:void(0); instead of #, which can prevent unnecessary page jumps;
If a function with a return value is called in the href attribute of the link, the current page The content will be replaced by the return value of this function;
There will be a difference when the Shift key is held down.
The problem I encountered today is that I cannot access parentNode in the form of href in IE6.0.
Try not to use javascript: protocol as the href attribute of A. This will not only cause unnecessary triggering of the window.onbeforeunload event, but will also stop the playback of animated gif images in IE.
Related recommendations:
a link refresh page and js refresh page usage
The above is the detailed content of How to prevent hyperlink from jumping when using a link. For more information, please follow other related articles on the PHP Chinese website!