首頁 > web前端 > js教程 > `javascript:void(0)` 實際上做了什麼?

`javascript:void(0)` 實際上做了什麼?

Patricia Arquette
發布: 2024-12-18 15:59:20
原創
613 人瀏覽過

What Does `javascript:void(0)` Actually Do?

解開「javascript:void(0)」之謎

JavaScript,一種在Web 開發中廣泛使用的無處不在的程式語言,提供了各種各樣的內建運算符,每個運算符都有特定的用途。一個引起許多人好奇的運算子是神秘的「void」運算符,經常在程式碼片段中遇到,例如:

```

What exactly does this operator entail?

**Understanding the Void Operator**

The void operator in JavaScript has a peculiar function. When applied to an expression, it evaluates the expression and returns a special value - undefined.

**Why Use the Void Operator in "javascript:void(0)"?**

The void operator is often employed in conjunction with the "javascript:" URL schema. When applied to an anchor's href attribute, as in the example above, the purpose is to prevent execution and display of the evaluation result.

**A Practical Application**

Consider the typical scenario of a web page that includes a link for user login. By default, a javascript: URL would prompt the browser to redirect to a plain text version of the JavaScript evaluation output, such as "undefined." However, by utilizing void(0) as the href value, the link's click action will not cause redirection.
登入後複製

以上是`javascript:void(0)` 實際上做了什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板