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

詳解a標(biāo)簽添加onclick事件的幾種方式

 更新時(shí)間:2019年03月29日 09:13:00   作者:manny-liu  
這篇文章主要介紹了a標(biāo)簽添加onclick事件的幾種方式,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

我們常用的在a標(biāo)簽中有點(diǎn)擊事件:

1. a href="javascript:js_method();" rel="external nofollow"

這種方法在傳遞this等參數(shù)的時(shí)候很容易出問題,而且javascript:協(xié)議作為a的href屬性的時(shí)候不僅會(huì)導(dǎo)致不 必要的觸發(fā)window.onbeforeunload事件,在IE里面更會(huì)使gif動(dòng)畫圖片停止播放。W3C標(biāo)準(zhǔn)不推薦在href里面執(zhí)行 javascript語(yǔ)句

2. a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" onclick="js_method()"

這種方法是很多網(wǎng)站最常用的方法,也是最周全的方法,onclick方法負(fù)責(zé)執(zhí)行js函數(shù),而void是一個(gè)操作符,void(0)返回undefined,地址不發(fā)生跳轉(zhuǎn)。而且這種方法不會(huì)像第一種方法一樣直接將js方法暴露在瀏覽器的狀態(tài)欄。

3.a href="javascript:;" rel="external nofollow" rel="external nofollow" onclick="js_method()"

這種方法跟跟2種類似,區(qū)別只是執(zhí)行了一條空的js代碼。

4.a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="js_method()"

這種方法也是網(wǎng)上很常見的代碼,#是標(biāo)簽內(nèi)置的一個(gè)方法,代表top的作用。所以用這種方法點(diǎn)擊后網(wǎng)頁(yè)后返回到頁(yè)面的最頂端。

5.a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="js_method();return false;"

這種方法點(diǎn)擊執(zhí)行了js函數(shù)后return false,頁(yè)面不發(fā)生跳轉(zhuǎn),執(zhí)行后還是在頁(yè)面的當(dāng)前位置。

綜合上述,在a中調(diào)用js函數(shù)最適當(dāng)?shù)姆椒ㄍ扑]使用:
a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" onclick="js_method()"

a href="javascript:;" rel="external nofollow" rel="external nofollow" onclick="js_method()"

a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="js_method();return false;"

以上所述是小編給大家介紹的a標(biāo)簽添加onclick事件的幾種方式詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論