亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

說明:

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

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

推薦寫法:javascript:;

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

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

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

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

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

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

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

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

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

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

而javascript:void(0) 僅僅表示一個(gè)死鏈接這就是為什么有的時(shí)候頁(yè)面很長(zhǎng)瀏覽鏈接明明是??墒翘鴦?dòng)到了頁(yè)首

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

使用javascript的方法(下面的這些用法會(huì)報(bào)錯(cuò))

<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ù)了。

若有不足請(qǐng)多多指教!希望給您帶來幫助!

總結(jié)

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

相關(guān)文章

最新評(píng)論