js取消頁面超鏈接的方法

n5em 9年前發布 | 2K 次閱讀 JavaScript

     <?php
header('content-type:text/html;charset=utf-8');

 ?>  

<A href="http://www.baidu.com" >百度</A>    <A href="http://www.jb51.net" >腳本之家</A>   
<A href="http://s.jb51.net" >服務器軟件</A>    <A href="http://sc.jb51.net" > 素材下載</A>   
<A href="http://tools.jb51.net" >站長查詢</A>    <A href="http://www.jb51.net/jiaoben/" >腳本下載</A>   
<input type=button id=o1 value="取消所有鏈接" onclick="javascript:doLinkAll(false)">   
<input type=button id=o2 value="重新設置鏈接" onclick="javascript:doLinkAll(true)">   
<script>   
function doLinkAll(action){   
var arr=document.getElementsByTagName("A")   
for(var i=0;i <arr.length;i++){   
if (action){ //重新設置鏈接   
if (arr[i].rel) arr[i].setAttribute("href",arr[i].rel)   
}else{ //取消所有鏈接   
arr[i].setAttribute("rel",arr[i].href)   
arr[i].removeAttribute("href")   
}   
}   
o1.disabled=!action   
o2.disabled=action   
}   
</script>   </pre> 


 本文由用戶 n5em 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!