Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the href attribute of a tag and onclick event in html

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use the href attribute of the a tag and the onclick event in html. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The a tag is mainly used to jump pages, either through the href attribute or in the onclick event.

PHP Chinese website

This code is fine in mainstream browsers, but it can't jump in IE6. What is the reason for this?

_ javascript:void (0)

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

test

test

IE6 first runs events bound by DOM itself, such as onclick;, which executes the href property sequentially if it does not prevent bubbling. While void (0); does not need to execute any event, IE6 tells the browser not to perform any event (overwriting the previous action), and ending bubbling is equivalent to returnfalse;, so the browser does not perform any action. So all you have to do is to stop bubbling within the onclick event.

PHP Chinese website

In this way, it can work properly under IE6.

Another way is not to use _ javascript:void (0); you can avoid using # instead. The # in the href attribute originally means anchor # name, so it goes to the top of the page when no anchor is specified. # has a specific meaning. The default is # top. If the content after # is considered to be a tag and jumps there from the page to find the corresponding tag, it will jump to the top of the page. If you do not want to jump, you can use #, # is a meaningless tag assignment.

Thank you for reading! This is the end of this article on "how to use the href attribute and onclick event of a tag in html". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report