<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)"
document.getElementsByTagName("A")[i].onclick=""
}
}
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="" onclick="alert()">AAA</a>
<a href="http://sina.com.cn" mxh="">AAA</a>
<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)"
document.getElementsByTagName("A")[i].onclick=""
}
}
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="" onclick="alert()">AAA</a>
<a href="http://sina.com.cn" mxh="">AAA</a>
<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)"
document.getElementsByTagName("A")[i].mxh2=document.getElementsByTagName("A")[i].onclick
document.getElementsByTagName("A")[i].onclick=""
}
}
function a2()
{
for(i=0;i<document.getElementsByTagName("A").length;i++){
document.getElementsByTagName("A")[i].href=document.getElementsByTagName("A")[i].mxh
document.getElementsByTagName("A")[i].onclick=document.getElementsByTagName("A")[i].mxh2
}
}
</script>
<a href="http://sina.com.cn" mxh="" mxh2="" onclick="alert()">AAA</a>
<a href="http://sina.com.cn" mxh="" mxh2="">AAA</a>
楼主何必跟自己过意不去,自己不写a 的 onclick事件,统统放在href中不就行了。
建议你干脆把所有的连接隐藏起来更好。
<form name=f>
<input type=button value="禁止" onclick="flag=false; ff()">
<input type=button value="恢复" onclick="flag=true; ff()">
</form>
<script>
var flag=true;
window.onload=ff;
function ff(){
var o=document.links
for(i=0;i<o.length;i++)
//o[i].onclick=new Function("return flag")
o[i].style.visibility = flag? "" : "hidden"
}
</script>
<a href="#1" mxh="">AAA</a>
<a href="#2" mxh="">AAA</a>
<<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<a name="1">test</a>
<a name="2">test</a>
为了贯彻落实秋水风格,照猫画虎的弄了一个:
<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.links;
for(i=0;i<o.length;i++){o[i].emu=o[i].onclick;o[i].onclick=new Function("if (flag) this.emu();return flag")}
}
</script>
<a href="http://www.csdn.net" onclick="alert(1)">AAA</a>
<a href="http://www.csdn.net" onclick="alert(2)">AAA</a>呵呵,象吧?
var fo = document.all.tags("A");
for(i=0;i<fo.length;i++){
if(fo[i].mxh == "inner"){
fo[i].href="#";
fo[i].disabled=true;
fo[i].onclick="";
}
}
}其中,href="#"和onclick=""绝对不能少的,刚试过的,还有一个就是,document.all.tags("A");好像不能用在一个form里面,刚才我用document.setForm.tags("A");就是不行的,有form名的形式对其他的tags就有用,但是这个A就是软硬不吃!所以我就用document.all.tags("A");,然后在setForm里面的所有标有<a...>加上了一个<a... mxh="inner"...>,最后就有上面的方法搞定了!
<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=o.length-1;i>-1;i--)
{
var s = document.createElement("<span></span>")
s.innerHTML = o[i].innerText;
s.emu=o[i].onclick;
s.href=o[i].href;
s.onclick=new Function("if (flag) try{this.emu()} finally{location=this.href}")
s.onmouseover=new Function("this.style.color='red'")
s.onmouseout=new Function("this.style.color='blue'")
s.style.color="blue"
s.style.cursor="hand"
o[i].replaceNode(s)
}
}
</script>
<a href="http://www.csdn.net" onclick="alert(1)">AAA</a>
<a href="http://www.csdn.net" onclick="alert(2)">AAA</a>