我在页面上显示一个层,怎样可以在用户点击层之外的区域时,将其隐藏。

livingagain 2002-01-29 10:05:40
加精
1.要求支持IE5;
2.该层中还有一些input,select等;
3.鼠标移出层区域,层并不发生变化。

分少了,但我已倾其所有。
...全文
165 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
livingagain 2002-01-29
  • 打赏
  • 举报
回复
给分,谢谢,能不能不通过body呢,
现在我在class中需要调用
document.body.attachEvent("onclick",this.id+".hidden()");
这样就无法达到我封装的目的了。
孟子E章 2002-01-29
  • 打赏
  • 举报
回复
<body onclick="if(window.event.srcElement.id !='mm'){ document.all.mxh.style.visibility='hidden';}">
<table cellpadding=0 cellspacing=0 border=0>
<tr>
<td style="border:3px groove #eeeeee;height:19px">
<input id=xh style="border:0px solid #080808;border-right:0px;height:18px"><input id="mm" style="font-family:Webdings;font-size:9pt;height:18px;" type=button value='6' onclick="document.all.mxh.style.visibility='visible'"></td>
</tr>
<tr>
<td>
<div id=mxh style="visibility:hidden;width:100%;border:1px solid #080808">
<table width="100%">
<tr onmouseover="this.style.backgroundColor='#0099ff'" onmouseout="this.style.backgroundColor=''">
<td onclick="document.all.xh.value=this.innerText"><a href="http://lucky.myrice.com">Visit1</a></td>
</tr>
<tr>
<td onmouseover="this.style.backgroundColor='#0099ff'" onmouseout="this.style.backgroundColor=''"onclick="document.all.xh.value=this.innerText"><a href="http://lucky.myrice.com">Visit2</a></td>
</tr>
<tr>
<td onmouseover="this.style.backgroundColor='#0099ff'" onmouseout="this.style.backgroundColor=''"onclick="document.all.xh.value=this.innerText"><a href="http://lucky.myrice.com">Visit3</a></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
livingagain 2002-01-29
  • 打赏
  • 举报
回复
再有,由于我是将其封装在一个由javascript写的class中,最好能不对document.body做任何操作。
livingagain 2002-01-29
  • 打赏
  • 举报
回复
可能我没表述清楚。
我想实现的类似select,点击右侧下拉按钮,显示下拉框。
当然这个下拉框里的东西比较多,比如说是个日历。
如果用户点击下拉框外的其他的地方,下拉框自动隐藏。
孟子E章 2002-01-29
  • 打赏
  • 举报
回复
<body onclick="if(window.event.srcElement.id !='mxh'){ document.all.mxh.style.visibility='hidden';document.all.sel.style.visibility='hidden'}">
<div id=mxh style="width:200px;height:200px;visibility:visible;background-color:blue;z-index:100" onclick="document.all.mxh.style.visibility='visible';document.all.sel.style.visibility='visible'">
<select id=sel style="visibility:visible">
<option>sdfd</option>
</select>
</div>
</body>

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧