Home > Web Front-end > JS Tutorial > The wonderful use of javascript void(0)_javascript skills

The wonderful use of javascript void(0)_javascript skills

WBOY
Release: 2016-05-16 18:44:04
Original
1075 people have browsed it

The void operator usage format is as follows:
1. javascript:void (expression)
2. javascript:void expression
expression is a JavaScript standard expression to be calculated. The parentheses outside the expression are optional, but it is a good practice to write them. We can specify hyperlinks using void operator. The expression is evaluated but nothing is loaded into the current document. The code above creates a hyperlink that does nothing when the user clicks on it. When the user clicks the link, void(0) evaluates to 0, but has no effect on JavaScript.
Nothing will happen if you click here
That is to say, if you want to perform some processing without refreshing the page as a whole, you can use void(0), but when needed When refreshing the page, be careful.

When calling this custom JS function, if we use click, although the method can be executed, if the page contains a scroll bar, it will automatically scroll to the top of the page. If At this time, we use click. When executed, the page will not scroll. This should be very useful for image switching and AJAX calls.

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