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
WBOYOriginal
2016-05-16 17:18:331105browse

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