<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{ margin:0; padding:0;}
body{ background:#CCC;}
li{ list-style:none;}
#wrapper{ position:relative; width:200px;margin:200px auto; background:#FFF;}
#wrapper .main{ float:left; width:170px; line-height:30px; background:#fff; padding-left:10px;}
#wrapper #btn{ float:right; width:20px; height:30px; background:#C03; cursor:pointer;}
ul{ position:absolute; left:0; top:30px; clear:both; width:198px;background:#FFF; border:1px solid #000; border-top:0; display:none;}
ul li{ padding-left:10px; line-height:30px;}
</style>
</head><body>
<div id="wrapper">
<div class="container">
<div class="main">北京</div>
<div id="btn"></div>
</div>
<ul id="list">
<li><a href="http://www.baidu.com" target="_blank">北京</a></li>
<li><a href="http://www.baidu.com" target="_blank">上海</a></li>
<li><a href="http://www.baidu.com" target="_blank">广州</a></li>
</ul>
</div>
<script type="text/javascript">
var Btn=document.getElementById("wrapper");
var List=document.getElementById("list");
Btn.onclick=function(){
List.style.display="block";
}
Btn.onmouseout=function(){
List.style.display="none";
}
</script>
</body>
</html>
为什么用Btn.onclick时,下面列表的内容鼠标无法选中,而改为onmouseover时,就可以了。如果想要Btn.onclick时,鼠标离开#list时,这个元素时再隐藏要怎么修改呢?
解决方案 »
- 动态菜单不能跨越xml文件?
- Javascript有什么方法可以实现调用客户端的命令呢?
- 1.html 如何把 2.html全包进来
- 大家好,一个很难js的问题
- 很棘手的一个问题,希望提供算法。
- insertRow()方法,在javascirpt哪个对象中能找到
- 表单验证小问题,请大家看看
- 关于时间问题。是这样,我用三个下拉选框来选择送到时间,有年,月,日,怎么控制选择完之后的时间不能小于当天的时间!
- open是打开窗口,如何让要open的页面在本页打开
- SCRIPT5007: 无法获取未定义或 null 引用的属性“animate”
- javascript怎样以绝对地址的方式取得frame
- 为什么取不到a元素
离开onmouseout
鼠标进入onmouseover
鼠标离开onmouseout
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
*{ margin:0; padding:0;}
body{ background:#CCC;}
li{ list-style:none;}
#wrapper{ position:relative; width:200px;margin:200px auto; background:#FFF;}
#wrapper .main{ float:left; width:170px; line-height:30px; background:#fff; padding-left:10px;}
#wrapper #btn{ float:right; width:20px; height:30px; background:#C03; cursor:pointer;}
ul{ position:absolute; left:0; top:30px; clear:both; width:198px;background:#FFF; border:1px solid #000; border-top:0; display:none;}
ul li{ padding-left:10px; line-height:30px;}
</style>
<script>
function $(id){return document.getElementById(id)}
</script>
</head><body>
<div id="wrapper">
<div class="container" onmouseout="$('list').style.display='none'" onmouseover="$('list').style.display='block'">
<div class="main">北京</div>
<div id="btn"></div>
</div>
<ul id="list">
<li><a href="http://www.baidu.com" target="_blank">北京</a></li>
<li><a href="http://www.baidu.com" target="_blank">上海</a></li>
<li><a href="http://www.baidu.com" target="_blank">广州</a></li>
</ul>
</div></body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
*{ margin:0; padding:0;}
body{ background:#CCC;}
li{ list-style:none;}
#wrapper{ position:relative; width:200px;margin:200px auto; background:#FFF;}
#wrapper .main{ float:left; width:170px; line-height:30px; background:#fff; padding-left:10px;}
#wrapper #btn{ float:right; width:20px; height:30px; background:#C03; cursor:pointer;}
ul{ position:absolute; left:0; top:30px; clear:both; width:198px;background:#FFF; border:1px solid #000; border-top:0; display:none;}
ul li{ padding-left:10px; line-height:30px;}
</style>
<script>
function $(id){return document.getElementById(id)}
</script>
</head><body>
<div id="wrapper" onmouseout="$('list').style.display='none'" onmouseover="$('list').style.display='block'">
<div class="container">
<div class="main">北京</div>
<div id="btn"></div>
</div>
<ul id="list">
<li><a href="http://www.baidu.com" target="_blank">北京</a></li>
<li><a href="http://www.baidu.com" target="_blank">上海</a></li>
<li><a href="http://www.baidu.com" target="_blank">广州</a></li>
</ul>
</div></body>
</html>