javascript基礎知識(14) void

來源:互聯網
上載者:User

標籤:資訊   get   java   efi   class   rnn   style   表達   href   

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

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

文法格式如下:

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

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

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

<a href="javascript:void(alert(‘Warning!!!‘))">點我!</a>

以下執行個體中參數 a 將返回 undefined :

function getValue(){  var a,b,c;  a = void ( b = 5, c = 7 );  document.write(‘a = ‘ + a + ‘ b = ‘ + b +‘ c = ‘ + c );}

void()僅僅是代表不返回任何值,但是括弧內的運算式還是要運行,如d:

void(alert("Wornning!"))

 

javascript基礎知識(14) void

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.