解决方案 »
- Highcharts already defined in the page
- 哪写错了 JQ,错了该怎么写?
- 有什么技术可以实现“ctrl+c”拷贝本地文件,在web里的文本框内"ctrl+v"就可以获得该文件的路径
- js高手,帮忙想想这个问题,考虑了好久,不知道如何解决!
- 小问题来拿分啦!!
- 如何用js模拟asp的encode,decode?在线等
- 如何控制文本框中最多能输入多少个字符(注意中文算两个英文算一个)?
- 怎样在IE打开的时候用JS隐藏IE的工具条
- 各位老大,能不能用javascript编一个记数器,可以的话帮忙编一个50分送上
- 请问高手--怎样提交<select multiple>..<option>..</select>多选框(用ctrl多选)内容
- jquery验证码问题
- 请教一个关于iframe的问题
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<TITLE>百度一下,你就知道</TITLE>
</head>
<style type="text/css">
.m{ border:1px solid #CCFF33; width:30px; float: right;
text-align: center;}
.z{border:1px dotted #00CCFF; width:50px;}
.z li{height: 15px; width: 150px;border: 1px solid #993300;}
ul{padding:0; margin:0; list-style:none; position:absolute;top:250px;left:300px;display: none;}
.kk{border: thin solid #006699; width: 250px; height: 50px;
position: relative; text-align: center;}
.body{text-align: center;}
</style>
<body>
<div class="kk" id="xx">x</div>
<div class="kk">y</div>
<ul class="z" id="sL">
<li><a href="http://www.163.com">yy</a></li>
<li><a href="http://www.163.com">yy</a></li>
<li><a href="http://www.163.com">yy</a></li>
<li><a href="http://www.163.com">yy</a></li>
<li><a href="http://www.163.com">yy</a></li>
</ul>
</body>
<script>
window.onload=function(){
document.getElementById('xx').onclick=function(){
document.getElementById("sL").style.display = "block";
}
var li=document.getElementById("sL").getElementsByTagName("li");
for(var i=0;i<li.length;i++)
{
li[i].onmouseover=function(){
this.style.background='red';
}
li[i].onmouseout=function(){
this.style.background='white';
} }
}
//document.onclick = function(e){
//var e = e||window.event,t = e.target||e.srcElement
//if(t.innerHTML=='x') return
//document.getElementById("sL").style.display = "none"
</script>
</html>这样可以吗。
你的原代码写得有点乱,一个CSS能完成的,却写了2个(一个标签,一个CLASS)。没有必要写那么复杂,尽量简化比较好。
document.getElementById('页面上任何一个标签元素').onclick=function(){
document.getElementById("sL").style.display = "none";
}
多加一条这个就能让其消失了!
多加下面这一条,鼠标经过也能触发了!
document.getElementById('xx').onmouseover=function(){
document.getElementById("sL").style.display = "block";
}
第1鼠标经过已经无触发,你想通过鼠标经过来触发UL显示,那么
什么意思? 是说显示ul后,只有点击页面其它地方才隐藏<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"> <!-- saved from url=(0021)http://www.HAO123.com/ --> <HTML><HEAD><TITLE>百度一下,你就知道</TITLE>
<META http-equiv=Content-Type content=text/html;charset=gb2312> </head>
<style type="text/css"> .m{ border:1px solid #CCFF33; width:30px; float: right; text-align: center;}
.z{border:1px dotted #00CCFF; width:50px; top: 48px; right: -169px; position:absolute; visibility: visible;}
.z li{height: 15px; width: 150px;border: 1px solid #993300;}
.z li a{display:block; height: 15px; width: 150px;}
ul{padding:0; margin:0; list-style:none; float: right; display: none;}
.kk{border: thin solid #006699; width: 250px; height: 50px; position: relative; text-align: center;}
.body{text-align: center;}</style>
<body>
<div class="kk">
<div class="m" onMouseOver="show()">x</div>
<ul class="z" id="sL" style="display: none;"> <li><a href="http://www.163.com">yy</a></li> <li><a href="http://www.163.com">yy</a></li> <li><a href="http://www.163.com">yy</a></li> <li><a href="http://www.163.com">yy</a></li> <li><a href="http://www.163.com">yy</a></li></ul> </div> <div class="kk"></div></body>
<script>
function show()
{ var tag = document.getElementById("sL")
if (tag.style.display=="none") { tag.style.display = "block" }}
document.onclick = function(e){ var e = e||window.event,t = e.target||e.srcElement;
if(t.innerHTML=='x') return;
document.getElementById("sL").style.display = "none"; }
window.onload=function(){
var lis = document.getElementById("sL").getElementsByTagName("li");
for(var i=0;i<lis.length;i++)
{
lis[i].onmouseover=function(){
this.style.backgroundColor='red';
}
lis[i].onmouseout=function(){
this.style.backgroundColor='white';
} } };
</script> </html>