Home > Web Front-end > HTML Tutorial > a tag href attribute and onclick event usage example_HTML/Xhtml_web page production

a tag href attribute and onclick event usage example_HTML/Xhtml_web page production

WBOY
Release: 2016-05-16 16:36:40
Original
1924 people have browsed it

The

a tag is mainly used to implement page jumps, which can be achieved through the href attribute or in the onclick event.

Copy code
The code is as follows:

This code is available in mainstream browsers No problem, but there will be a problem of not being able to jump under IE6. What is the reason for this?

Copy code
The code is as follows:

javascript:void(0);

void(arg); can be understood as a function that always returns null, but its parameters cannot be empty. Its parameters can be any expressions or even functions.

Copy code
The code is as follows:

Test

IE6 first runs events bound to the DOM itself, such as onclick; if bubbling is not prevented, href attributes will be executed sequentially. And void(0); does not need to execute any events, so IE6 tells the browser not to execute any events (overwriting previous actions), and terminating bubbling is equivalent to return false; so the browser does not execute any actions. So just stop the bubbling event within the onclick event.

Copy code
The code is as follows:

This way It can run normally under IE6.

Another method is not to use javascript:void(0); but to use # instead. This can also be avoided. The # in the href attribute originally means the anchor point #name, so when no anchor point is specified, the page will be reached. top. # has a specific meaning, and the default is #top. If there is content after #, it will be considered a tag and the corresponding tag will be jumped to there if found on the page. If it cannot be found, it will jump to the top of the page. If you do not want to jump, , you can use ###, ### is a meaningless label specification.

Related labels:
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