Home > Web Front-end > JS Tutorial > Example introduction to the role of javascript:void(0)_Basic knowledge

Example introduction to the role of javascript:void(0)_Basic knowledge

WBOY
Release: 2016-05-16 17:18:33
Original
1103 people have browsed it

When making a page, if you want to do nothing after clicking a link, or complete other things in response to the click, you can set its attribute href = "#". However, there will be a problem when the page has a scroll bar. , after clicking, it will return to the top of the page, or jump to the set anchor point, which is a bad user experience.

Usual usage is:

Copy code The code is as follows:

< ;a href="javascript:void(0)">Click here to see the effect

Actually nothing will happen if you click here, the javascript in it The :void(0); form is a pseudo-protocol of JavaScript, which means that this link will not jump to any place.

The main forms of using javascript:void(0) are as follows:
Copy code Code As follows:

//Do nothing after clicking the link
test
test
test //Use 2 to 4 #, most of them are " ####", and also use "#all" and other

Copy code The code is as follows:

//After clicking the link, respond to the user-defined click event
test
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