Home  >  Article  >  Web Front-end  >  Detailed explanation of a tag click event in javascript

Detailed explanation of a tag click event in javascript

零下一度
零下一度Original
2017-04-19 11:08:103237browse

This article will introduce in detail the relevant knowledge of the click event on the a tag. It has a very good reference value. Let’s take a look with the editor below

When we process the click event on the a tag, we find that even if href="" is empty, the effect of the click event It's not obvious. How to deal with this situation? Common handling methods are as follows:

a href="javascript:void(0);" rel="external nofollow" onclick="method()"

This method is the most commonly used method and the most comprehensive method. The onclick method is responsible for Execute js function, and void is an operator, void(0) returns undefined, and the address does not jump. And this method does not directly expose the js method to the browser's status bar like the first method.

a href="javascript:;" rel="external nofollow" onclick="method()"

This method is similar to the two methods, the only difference is that an empty js code is executed.

a href="#" rel="external nofollow" rel="external nofollow" onclick="method()"

This method is also a very common code on the Internet. # is a method built into the tag, representing the role of top. So using this method to click on the web page returns to the top of the page.

a href="#" rel="external nofollow" rel="external nofollow" onclick="method();return false;"

This method returns false after clicking to execute the js function, which prevents the default behavior of the event itself. The page does not jump, and it is still at the current position of the page after execution.

The above is the detailed content of Detailed explanation of a tag click event in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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