js取消页面超链接的方法javascript
<?php
header('content-type:text/html;charset=utf-8');
?>
<A href="http://www.baidu.com" >百度</A> <A href="http://www.jb51.net" &...
<?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>
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>
下一篇:JS正则验证邮箱的格式
我要评论