有时候某些界面上某个区域要限制原先链接的使用, 可以价格div 层,对整个层范围生效。
<div id="Layer1" onclick="return false;">
<table width="100px" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#999999">
<tr bgcolor="#f5f5f5">
<td><a href="http://www.sina.com.cn">新浪</a></td>
</tr>
<tr bgcolor="#f5f5f5">
<td><a href="http://www.163.com">网易</a></td>
</tr>
</table>
</div>
<script language="javascript">...
function method1()...{
}
function method2()...{
alert('无法点击链接');
}
function enableDiv()...{
var obj=document.getElementById("Layer1");
obj.style.filter='Alpha(Opacity=100)';
//obj.style.MozOpacity='1';
obj.onclick=new Function("method1();return true;");
}
function disableDiv() ...{
var obj=document.getElementById("Layer1");
obj.style.filter='Alpha(Opacity=30)';
//obj.style.MozOpacity='0.3';
obj.onclick=new Function("method2();return false;");
}
</script>
<br>
<input type="button" value="启用" onclick="enableDiv();" />
<input type="button" value="禁用" onclick="disableDiv();"/>
<table width="100px" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#999999">
<tr bgcolor="#f5f5f5">
<td><a href="http://www.sina.com.cn">新浪</a></td>
</tr>
<tr bgcolor="#f5f5f5">
<td><a href="http://www.163.com">网易</a></td>
</tr>
</table>
</div>
<script language="javascript">...
function method1()...{
}
function method2()...{
alert('无法点击链接');
}
function enableDiv()...{
var obj=document.getElementById("Layer1");
obj.style.filter='Alpha(Opacity=100)';
//obj.style.MozOpacity='1';
obj.onclick=new Function("method1();return true;");
}
function disableDiv() ...{
var obj=document.getElementById("Layer1");
obj.style.filter='Alpha(Opacity=30)';
//obj.style.MozOpacity='0.3';
obj.onclick=new Function("method2();return false;");
}
</script>
<br>
<input type="button" value="启用" onclick="enableDiv();" />
<input type="button" value="禁用" onclick="disableDiv();"/>