代码驿站移动版
频道导航
HTML/Xhtml
CSS
JavaScript
HTML5
PHP教程
ASP.NET
正则表达式
AJAX
ThinkPHP
Yii
MySQL
MariaDB
Oracle
MongoDB
Redis
DedeCMS
PHPCMS
帝国CMS
WordPress
Discuz
其它CMS
Zend Studio
Sublime
Notepad
Dreamweaver
Windows
Linux
Nginx
Apache
IIS
CentOS
Ubuntu
Debian
网站优化
工具资源
PHP源码
ASP.NET源码
其它源码
图标素材
按钮素材
字体素材
DedeCMS模板
帝国CMS模板
PHPCMS模板
WordPress模板
Discuz!模板
单页模板
开发软件下载
服务器软件下载
广告投放
联系我们
版权申明
软件编程
网页前端
移动开发
数据库
服务器
脚本语言
PHP代码
JAVA代码
Python代码
Android代码
当前位置:
主页
>
网页前端
>
JavaScript代码
>
js实现的点击超链显示隐藏层
时间:2021-04-07 10:11:57 | 栏目:
JavaScript代码
| 点击:次
点击链接,显示提示框,提示框里也有链接可点击.
鼠标移开链接或者移开提示框,提示框就隐藏。
下面这个我写的不能自适应,如果菜单左对齐,显示层能否自动在右边显示?应该怎样调整JS?
<!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>test</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" 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>1sty人的和lesdf人的和人的和11</td> <td>人的和人的和人的和人的和人的和</td> <td>33人的和人的和人的和人的和3</td> <td>44人的和人的和人的和人的和人的和人的和人的和人的和4</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>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
左对齐效果
<!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>test</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>1sty人的和lesdf人的和人的和11</td> <td>人的和人的和人的和人的和人的和</td> <td>33人的和人的和人的和人的和3</td> <td>44人的和人的和人的和人的和人的和人的和人的和人的和4</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>
[Ctrl+A 全选 注:
引入外部Js需再刷新一下页面才能执行
]
您可能感兴趣的文章:
JavaScript常见事件处理程序实例总结
Javascript的匿名函数小结
url传递的参数值中包含&时,url自动截断问题的解决方法
javascript上下左右定时滚动插件
Javascript别踩白块儿(钢琴块儿)小游戏实现代码
相关文章
11-08
兼容浏览器的js事件绑定函数(详解)
11-23
Webpack中loader打包各种文件的方法实例
11-27
Javascript实例教程(19) 使用HoTMetal(2)
10-05
javascript判断图片是否加载完成的方法推荐
11-22
在javascript中执行任意html代码的方法示例解读
JQuery
VUE
AngularJS
MSSql
MySQL
MongoDB
Redis
Linux
Tomcat
Nginx
网站首页
广告投放
联系我们
版权申明
联系站长