javascript:void(0) 含義

來源:互聯網
上載者:User

標籤:href   操作   代碼   logs   java   text   ...   使用   何事   

我們經常會使用到 javascript:void(0) 這樣的代碼,那麼在 JavaScript 中 javascript:void(0) 代表的是什麼意思呢?

javascript:void(0) 中最關鍵的是 void 關鍵字, void 是 JavaScript 中非常重要的關鍵字,該操作符指定要計算一個運算式但是不傳回值。

文法格式如下:

<head><script type="text/javascript"><!--void func()javascript:void func()或者void(func())javascript:void(func())//--></script></head>

 下面的代碼建立了一個超級連結,當使用者點擊以後不會發生任何事。

<a href="javascript:void(0)">單擊此處什麼也不會發生</a> 

 

 

當使用者連結時,void(0) 計算為 0,但 Javascript 上沒有任何效果。

以下執行個體中,在使用者點選連結後顯示警告資訊:

<head><script type="text/javascript"><!--//--></script></head><body><a href="javascript:void(alert(‘Warning!!!‘))">點我!</a></body> 

 

 href="#"與href="javascript:void(0)"的區別

# 包含了一個位置資訊,預設的錨是#top 也就是網頁的上端。

而javascript:void(0), 僅僅表示一個死連結。

在頁面很長的時候會使用 # 來定位頁面的具體位置,格式為:# + id

如果你要定義一個死連結請使用 javascript:void(0) 。

<a href="javascript:void(0);">點我沒有反應的!</a><a href="#pos">點我定位到指定位置!</a><br>...<br><p id="pos">尾部錨點</p> 

 

javascript:void(0) 含義

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.