JavaScript Void(0)是什么意思?

JavaScript provides the operator void in order to return undefined results as a result of a function. void also used to evaluate and return undefined result for an expression.

JavaScript为操作员提供了void ,以便返回由于函数而导致的未定义结果。 void还用于评估表达式并返回undefined结果。

虚空运算符 (Void Operator)

In the general void is used to specify the function return type as nothing or undefined where the function really returns nothing. This function will only execute some statements and evaluate expressions but return nothing.

在一般情况下,void用于将函数返回类型指定为none或undefined,其中函数实际上什么都不返回。 此函数将仅执行一些语句并计算表达式,但不返回任何内容。

void function log_message() 
{
  console.log("Executed!"); 
}();

无效(0)用例 (Void(0) Use Cases)

void(0) can be used as javascript: URI, where the URI will be evaluated and resulting value or content, will be printed on the page. For example, the following <a> tag will contain This is content .

void(0)可用作javascript: URI,将在其中评估URI并将结果值或内容打印在页面上。 例如,以下<a>标记将包含This is content

<a href="javascript:void(0);">
  This is content 
</a>

javascript:void(0)范例 (javascript:void(0) Example)

In the following example, we will put javascript:void(0) in anchor tag which will prevent the page reload when it is clicked.

在以下示例中,我们将javascript:void(0)放在锚标记中,这将防止在单击页面时重新加载页面。

<html>
   <head>
      <title>JavaScript:void(0) Example</title>
   </head>
   <body>
      <center>
         <h1 style="color:green">Poftut.com</h1>
         <h3>JavaScript:void(0)</h3>
         <a href="javascript:void(0);"
            ondblclick="alert('Welcome to Our Page')">
         Double click on me </a>
      </center>
   </body>
</html>

翻译自: https://www.poftut.com/what-does-javascript-void0-mean/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值