How to use a tag href attribute and onclick event

php中世界最好的语言
Release: 2018-01-25 11:21:39
Original
2323 people have browsed it

This time I will show you how to use the a tag href attribute andonclickevent. What are theprecautionswhen using the a tag href attribute and onclick event? Which ones, the following are practical cases, let’s take a look. The

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

PHP中文网
Copy after login

This code is fine in mainstream browsers, but there will be a problem that it cannot jump under IE6. What is the reason for this?

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 anyexpressionor even a function.

测试
Copy after login

Test

IE6 first runs the events bound to the DOM itself, such as onclick; if bubbling is not prevented, the 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.

PHP中文网
Copy after login

This way it can run normally under IE6.

Another way is to avoidusing javascript:void(0); instead using #. The # in the href attribute originally meansanchor point#name So when no anchor is specified, it will go to the top of the page. # 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.

I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:
How to use horizontal line annotations and code comments in HTML


How to write flexible, stable, High-quality HTML and css code

##How to achieve the effect of clicking the button text into an input box, and clicking save to turn it into text

###

The above is the detailed content of How to use a tag href attribute and onclick event. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!