<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>emu</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function disableAnchor()
{
var ar = document.getElementsByTagName("A");
for (var i=0;i<ar.length;i++)
{
ar[i].disabled=true
ar[i].tHref=ar[i].href
ar[i].href="#"
ar[i].tTarget=ar[i].target
ar[i].target="_self"
}
}
function enableAnchor()
{
var ar = document.getElementsByTagName("A");
for (var i=0;i<ar.length;i++)
{
ar[i].disabled=false
ar[i].href=ar[i].tHref
ar[i].target=ar[i].tTarget
}
}
//-->
</SCRIPT>
</head>
<body>
<a href="http://www.csdn.net" target="_blank">test</a><BR>
<a href="http://www.csdn.net" target="_blank">test</a><BR>
<a href="http://www.csdn.net" target="_blank">test</a><BR>
<a href="http://www.csdn.net" target="_blank">test</a><BR>
<button onclick=disableAnchor()>disable</button>
<button onclick=enableAnchor()>ensable</button>
</body>
</html>

解决方案 »

  1.   

    <form name=f>
    <input type=button value="禁止" onclick="a()">
    <input type=button value="恢复" onclick="a2()">
    </form>
    <script>
    function a()
    {
    for(i=0;i<document.getElementsByTagName("A").length;i++)
    {
    document.getElementsByTagName("A")[i].mxh=document.getElementsByTagName("A")[i].href
    document.getElementsByTagName("A")[i].href="Javascript:void(0)"
    }
    }function a2()
    {
    for(i=0;i<document.getElementsByTagName("A").length;i++)
    document.getElementsByTagName("A")[i].href=document.getElementsByTagName("A")[i].mxh
    }
    </script>
    <a href="http://sina.com.cn" mxh="">AAA</a>
    <a href="http://sina.com.cn" mxh="">AAA</a>
      

  2.   

    禁止/恢复所有链接(包括map)
    <form name=f>
    <input type=button value="禁止" onclick="a()">
    <input type=button value="恢复" onclick="a2()">
    </form>
    <script>
    function a()
    {
    for(i=0;i<document.links.length;i++)
    {
    document.links[i].mxh=document.links[i].href;
    document.links[i].href="Javascript:void(0)";
    }
    }function a2()
    {
    for(i=0;i<document.links.length;i++)
    document.links[i].href=document.links[i].mxh
    }
    </script>
    <a href="#1" mxh="">AAA</a>
    <a href="#2" mxh="">AAA</a>
    <p>&nbsp;
    <p>&nbsp;
    <p>&nbsp;
    <p>&nbsp;
    <p>&nbsp;
    <a name="1">test</a>
    <a name="2">test</a>
      

  3.   

    href="Javascript:void(0)"
    还是你写的好看。
      

  4.   

    <form name=f>
    <input type=button value="禁止" onclick="flag=false">
    <input type=button value="恢复" onclick="flag=true">
    </form>
    <script>
    var flag=true;
    function window.onload(){
    var o=document.getElementsByTagName("A")
    for(i=0;i<o.length;i++)o[i].onclick=new Function("return flag")
    }
    </script>
    <a href="http://sina.com.cn">AAA</a>
    <a href="http://sina.com.cn">AAA</a>