Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use javascript's void

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how to use javascript's void". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Other people's JavaScript scripts can see code like this:

Here

But what exactly does void (0) mean here?

Void in JavaScript is an operator that specifies that an expression is evaluated but does not return a value.

The usage format of the void operator is as follows:

1. _ javascript:void (expression)

2. _ javascript:void expression

Expression is an expression of the JavaScript standard to evaluate. The parentheses on the outside of the expression are optional, but it is a good habit to write them.

You can use the void operator to specify hyperlinks. The expression is evaluated but nothing is loaded in the current document.

The following code creates a hyperlink that nothing happens when the user clicks. When the user clicks on the link, void (0) is calculated as 0, but has no effect on JavaScript.

Click here and nothing will happen.

The following code creates a hyperlink that submits the form when the user clicks.

Click here to submit the form

The default anchor for # containing location information is # top, the top of the page, while _ javascript:void (0) simply represents a dead link. This is why sometimes the page is very long and the browsing link is obviously # but jumps to the top of the page, but this is not the case with _ javascript:void (0), so it is best to use void (0) when calling the script, or so on.

Void operator

Avoid the expression returning a value.

The expression parameter is any valid JScript expression.

Description

The void operator evaluates the expression and returns undefined. This operator is most useful when you want to find the value of an expression but do not want the rest of the script to see the result

That's all for "how to use javascript's void". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report