Home > Web Front-end > JS Tutorial > body text

Detailed explanation of a tag click event in javascript

零下一度
Release: 2017-04-19 11:08:10
Original
3258 people have browsed it

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()"
Copy after login

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()"
Copy after login

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()"
Copy after login

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;"
Copy after login

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!

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