Introduction to how to prevent hyperlink jumps when using a link

高洛峰
Release: 2017-03-06 17:04:33
Original
2191 people have browsed it

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 got the following conclusion 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);
Assuming 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 the window.onbeforeunload event to be triggered unnecessarily, but will also cause the gif animated image to stop playing in IE.

For more related articles on how to prevent hyperlink jumps when using a link, please pay attention to the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template