<HTML>
<BODY>
<div id=mydiv onmouseout='cls()' style="width:200px;height:200px;background-color:seashell">
<table cellpadding="0" cellspacing="0" border="1" frame=box>
<tr style="height:30px"><td>密码管理</td></tr>
<tr style="height:30px"><td>外观选择</td></tr>
<tr style="height:30px"><td>权限设置</td></tr>
<tr style="height:30px"><td>退出系统</td></tr>
</table>
</div>
<input name=dd type=button value='显示层' onclick=showdiv()>
</BODY>
</HTML>
<script>
/*
怎样才能做到,只要鼠标离开层,层才会隐藏,否则一直显示
下面方法只可在IE中运行但在NS却不运行
怎样改可即在IE中运行也可在NS中运行
*/
function cls()
{
var div = document.getElementById("mydiv")
div.style.visibility='hidden'
}
function showdiv()
{
var div = document.getElementById("mydiv")
div.style.visibility='visible'
}</script>
<BODY>
<div id=mydiv onmouseout='cls()' style="width:200px;height:200px;background-color:seashell">
<table cellpadding="0" cellspacing="0" border="1" frame=box>
<tr style="height:30px"><td>密码管理</td></tr>
<tr style="height:30px"><td>外观选择</td></tr>
<tr style="height:30px"><td>权限设置</td></tr>
<tr style="height:30px"><td>退出系统</td></tr>
</table>
</div>
<input name=dd type=button value='显示层' onclick=showdiv()>
</BODY>
</HTML>
<script>
/*
怎样才能做到,只要鼠标离开层,层才会隐藏,否则一直显示
下面方法只可在IE中运行但在NS却不运行
怎样改可即在IE中运行也可在NS中运行
*/
function cls()
{
var div = document.getElementById("mydiv")
div.style.visibility='hidden'
}
function showdiv()
{
var div = document.getElementById("mydiv")
div.style.visibility='visible'
}</script>
function lib_bwcheck(){ //兼容性处理代码
this.ver=navigator.appVersion;
this.agent=navigator.userAgent
this.dom=document.getElementById?1:0
this.win = (navigator.appVersion.indexOf("Win")>0);
this.xwin = (navigator.appVersion.indexOf("X11")>0);
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
this.ie4=(document.all && !this.dom)?1:0;
this.ie=this.ie4||this.ie5||this.ie6
this.mac=this.agent.indexOf("Mac")>-1
this.opera5=this.agent.indexOf("Opera 5")>-1
this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
this.ns4=(document.layers && !this.dom)?1:0;
this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.dom||false);
this.width = null;
this.height = null;
return this
}var bw = new lib_bwcheck();function getObjectById( ID ) {
if (bw.ns6) return document.getElementById(ID);
else if (bw.ns) return document.layers[ID];
else return document.all[ID];
}
<div id="mydiv" name="mydiv" onmouseout="cls();" style="width:200px;height:200px;background-color:seashell">//注意,你的原来代码中cls()部分的引号不对的。
此外你最好跟踪调试一下程序。
<head>
<script>
function lib_bwcheck(){ //兼容性处理代码
this.ver=navigator.appVersion;
this.agent=navigator.userAgent
this.dom=document.getElementById?1:0
this.win = (navigator.appVersion.indexOf("Win")>0);
this.xwin = (navigator.appVersion.indexOf("X11")>0);
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
this.ie4=(document.all && !this.dom)?1:0;
this.ie=this.ie4||this.ie5||this.ie6
this.mac=this.agent.indexOf("Mac")>-1
this.opera5=this.agent.indexOf("Opera 5")>-1
this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
this.ns4=(document.layers && !this.dom)?1:0;
this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.dom||false);
this.width = null;
this.height = null;
return this
}var bw = new lib_bwcheck();function getObjectById( ID ) {
if (bw.ns6) return document.getElementById(ID);
else if (bw.ns) return document.layers[ID];
else return document.all[ID];
}
</script>
</head>
<BODY>
<div id=mydiv onmouseout='cls()' style="width:200px;height:200px;background-color:seashell">
<table cellpadding="0" cellspacing="0" border="1" frame=box>
<tr style="height:30px"><td>密码管理</td></tr>
<tr style="height:30px"><td>外观选择</td></tr>
<tr style="height:30px"><td>权限设置</td></tr>
<tr style="height:30px"><td>退出系统</td></tr>
</table>
</div>
<input name=dd type=button value='显示层' onclick=showdiv()>
</BODY>
</HTML>
<script>
/*
怎样才能做到,只要鼠标离开层,层才会隐藏,否则一直显示
下面方法只可在IE中运行但在NS却不运行
怎样改可即在IE中运行也可在NS中运行
*/
function cls()
{
var div = getObjectById("mydiv")
div.style.visibility='hidden'
}
function showdiv()
{
var div = getObjectById("mydiv")
div.style.visibility='visible'
}</script>
-------------------
上面的代码在IE6和firefox1.5Bate2上的显示效果完全一样。
onmouseover 事件,层会自动隐藏,所以用componentFromPoint判断,当前的鼠标是否在控件层中,但此方法却在NC中不运行!此问题难住我两天了---急啊