js实现点击超链显示与隐藏层的代码

发布时间:2019-12-09编辑:脚本学堂
用js代码实现点击超链接时显示与隐藏div层,有需要的朋友,可以参考下。

本文介绍的代码,实现如下功能:
1)、点击链接,显示提示框,提示框里也有链接可点击。
2)、鼠标移开链接或移开提示框,提示框就隐藏。

代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>点击超链接实现层的显示与隐藏-www.jb200.com</title>
</head>
<style>
body {background-color: #fff; font-size:14px; color:#666;}
#link-url a {display:block; height:30px; line-height:30px;width:100px; color:#666; text-decoration:none;cursor:pointer;}
#link-url a:hover {background:#ccc;}
#d-k{position:relative; margin:0px 0px 0px 0px;z-index:0;}
#Layer1,#Layer2,#Layer3,#Layer4,#Layer5{position:absolute; left: 70px; top: 0px;right:70px;}
#show-k{margin:0px 0px 0px 0px;position:relative;background-color:#000; border:#ccc 1px solid; height:100px;z-index:3;filter:alpha(opacity=70);opacity:0.7; width:500px;}
</style>
<script language="javascript">
function change(x) {document.getElementById(x).style.display ="none";}
function onClickbox(y){document.getElementById(y).style.display ="";}
function onMouseOutbox(z){document.getElementById(z).style.display ="none";}
function onMouseOverbox(a){document.getElementById(a).style.display ="";}
</script>
<body>
<div id="link-url" >
<table width="400" align="right" cellspacing="5">
<tr>
<td>
<div id="d-k">
<a onclick="onClickbox('Layer1');" onMouseOut="onMouseOutbox('Layer1')">我点击一</a>
<div id="Layer1" style="display:none;" onMouseOver="onMouseOverbox('Layer1')" onMouseOut="onMouseOutbox('Layer1')">
<div id="show-k">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>脚本学堂_www.jb200.com</td>
<td>105-4412-855</td>
<td>脚本学堂_www.jb200.com</td>
<td>脚本学堂_www.jb200.com</td>
</tr>
</table>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div id="d-k">
<a onClick="onClickbox('Layer2')" onMouseOut="onMouseOutbox('Layer2')">我点击一</a>
<div id="Layer2" style="display:none;" onMouseOver="onMouseOverbox('Layer2')" onMouseOut="onMouseOutbox('Layer2')">
<div id="show-k">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="#" onClick="change('Layer2')">111</a></td>
<td><a href="#" onClick="change('Layer2')">222</a></td>
<td><a href="#" onClick="change('Layer2')">333</a></td>
<td><a href="#" onClick="change('Layer2')">444</a></td>
</tr>
</table>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div id="d-k">
<a onClick="onClickbox('Layer3')" onMouseOut="onMouseOutbox('Layer3')">我点击一</a>
<div id="Layer3" style="display:none;" onMouseOver="onMouseOverbox('Layer3')" onMouseOut="onMouseOutbox('Layer3')">
<div id="show-k">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="#" onClick="change('Layer3')">111</a></td>
<td><a href="#" onClick="change('Layer3')">222</a></td>
<td><a href="#" onClick="change('Layer3')">333</a></td>
<td><a href="#" onClick="change('Layer3')">444</a></td>
</tr>
</table>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div id="d-k">
<a onClick="onClickbox('Layer4')" onMouseOut="onMouseOutbox('Layer4')">我点击一</a>
<div id="Layer4" style="display:none;" onMouseOver="onMouseOverbox('Layer4')" onMouseOut="onMouseOutbox('Layer4')">
<div id="show-k">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="#" onClick="change('Layer4')">111</a></td>
<td><a href="#" onClick="change('Layer4')">222</a></td>
<td><a href="#" onClick="change('Layer4')">333</a></td>
<td><a href="#" onClick="change('Layer4')">444</a></td>
</tr>
</table>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div id="d-k">
<a onClick="onClickbox('Layer5')" onMouseOut="onMouseOutbox('Layer5')">我点击一</a>
<div id="Layer5" style="display:none;" onMouseOver="onMouseOverbox('Layer5')" onMouseOut="onMouseOutbox('Layer5')">
<div id="show-k">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="#" onClick="change('Layer5')">111</a></td>
<td><a href="#" onClick="change('Layer5')">222</a></td>
<td><a href="#" onClick="change('Layer5')">333</a></td>
<td><a href="#" onClick="change('Layer5')">444</a></td>
</tr>
</table>
</div>
</div>
</div>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>