欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascriptvoid(0)含義以及與"#"的區(qū)別講解

 更新時間:2019年01月19日 10:37:13   作者:muzidigbig  
今天小編就為大家分享一篇關(guān)于javascriptvoid(0)含義以及與"#"的區(qū)別講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

javascript:void(0) 中最關(guān)鍵的是 void 關(guān)鍵字, void 是 JavaScript 中非常重要的關(guān)鍵字,該操作符指定要計算一個表達(dá)式但是無返回值。

說明:

  • 1.javascript:void(0)這種偽協(xié)議,少寫的好,如果你看過一些web標(biāo)準(zhǔn)的書就知道為什么了。(不懂,原話摘的,暫做記錄)
  • 2.鏈接(href)直接使用javascript:void(0)在IE中可能會引起一些問題,比如:造成gif動畫停止播放等,所以,最安全的辦法還是使用“####”。為防止點(diǎn)擊鏈接后跳轉(zhuǎn)到頁首,onclick事件return false即可。
  • 3.如果僅僅是想鼠標(biāo)移過,變成手形,可以使用

<span style="cursor:pointer" onclick="foo()">Click Me!</span>  

推薦寫法:javascript:;

為什么要使用href=”javascript:void(0);”

href=”javascript:void(0);”這個的含義是,讓超鏈接去執(zhí)行一個js函數(shù),而不是去跳轉(zhuǎn)到一個地址,而void(0)表示一個空的方法,也就是不執(zhí)行js函數(shù)。

javascript:是偽協(xié)議,表示url的內(nèi)容通過javascript執(zhí)行。

void(0)表示不作任何操作,這樣會防止鏈接跳轉(zhuǎn)到其他頁面。這么做往往是為了保留鏈接的樣式,但不讓鏈接執(zhí)行實(shí)際操作,

<a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="window.open()"> 點(diǎn)擊鏈接后,頁面不動,只打開鏈接

<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="javascript:return false;"> 作用一樣,但不同瀏覽器會有差異。

href=”#"的區(qū)別(谷歌瀏覽器)

<a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" >點(diǎn)擊</a>點(diǎn)擊鏈接后不會回到網(wǎng)頁頂部

<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >點(diǎn)擊</a> 點(diǎn)擊后會回到網(wǎng)面頂部,并會在地址欄的后面加個 #

"#"其實(shí)是包含了位置信息,例如默認(rèn)的錨點(diǎn)是#top 也就是網(wǎng)頁的上端

而javascript:void(0) 僅僅表示一個死鏈接這就是為什么有的時候頁面很長瀏覽鏈接明明是??墒翘鴦拥搅隧撌?/p>

而javascript:void(0) 則不是如此所以調(diào)用腳本的時候最好用void(0)

使用javascript的方法(下面的這些用法會報錯)

<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="javascript:方法;return false;">文字</a>

<a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="javascript:方法;return false;">文字</a>

補(bǔ)充 :<a href="javascript:fn();" rel="external nofollow" 這樣點(diǎn)擊a標(biāo)簽就可以執(zhí)行fn()函數(shù)了。

若有不足請多多指教!希望給您帶來幫助!

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接

相關(guān)文章

最新評論