如何点击按钮显示一个DIV,点击页面其它地方隐藏这个DIV? 如何点击按钮显示一个DIV,点击页面其它地方隐藏这个DIV 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果只是ie浏览器在div onblur的时候添 隐藏div就好了如果还要估计其他浏览器那就给document添加onmousedown事件吧隐藏后记得把document的onmousedown事件清楚掉 在按按纽的时候在添加 document事件 给这个<div>定义一个ID="a"$("div [id=a]").hide();显示用show() <DIV ID="divID"> Hello word </div>隐藏用hide()$("#divID").hide();显示用show()$("#divID").show(); <html><head><style>body{padding:0px;margin: 0 auto;}</style><script>function show(e){ e = e || event; if(e.stopPropogation){ alert(1); e.stopPropogation(); }else{ e.cancelBubble = true; } document.getElementById("content1").style.display = "";}function init(){ document.body.onmousedown = function(){ document.getElementById("content1").style.display = "none"; };}</script></head><body onload="init()"><input type="button" value="显示" onclick="show(event)"/><div id="content1" style="display:none">关注排行1. 关注排行12. 关注排行23. 关注排行34. 关注排行4</div></body></html> 给这个 <div>定义一个ID="a" $("div [id=a]").hide();显示用show() <html><head> <title>test</title> <script type="text/javascript"> function show(oEvent){ document.getElementById("a").style.display = "block"; e = window.event || oEvent; if (e.stopPropagation) { e.stopPropagation(); }else{ e.cancelBubble = true; } } function hide(){ document.getElementById("a").style.display = "none"; } </script></head><body onclick="hide();"><input type="button" onclick = "show();" /><div id="a">test</div></body></html> 上面搞错了,在FF下不能用:<html><head> <title>test</title> <script type="text/javascript"> function show(oEvent){ document.getElementById("a").style.display = "block"; e = window.event || oEvent; if (e.stopPropagation) { e.stopPropagation(); }else{ e.cancelBubble = true; } } function hide(){ document.getElementById("a").style.display = "none"; } window.onload = function(){ document.body.onclick = hide; document.getElementById("c").onclick = show; }; </script></head><body><input id="c" type="button" value="ClickMe" /><div id="a">test</div></body></html> event.target来判断在那个srcElement下面 为什么这样定义数组for ..in遍历就不执行 file 获取 上传图片路径 问题 js判断table中显示的行数 改的了innerHTML却改不了color? 有办法用js获取用户IP吗?不使用Active控件-安全警告问题 菜鸟求解..为什么同一对象value属性一个有值一个没有值显示为on 急问题:用js能否打印某个文档 我正在做一项统计js各方面通用函数的工作,做成一个js比较全面的库,以便提高大家工作效率,届时我会在此版发布,为大家提供下载,现征集 请大家帮忙看看这段代码?谢谢! 求大神帮忙 追加一行 svg 鼠标坐标
在div onblur的时候添 隐藏div就好了如果还要估计其他浏览器
那就给document添加onmousedown事件吧隐藏后记得把document的onmousedown事件清楚掉 在按按纽的时候在添加 document事件
$("div [id=a]").hide();显示用show()
$("#divID").hide();显示用show()
$("#divID").show();
<head>
<style>
body{
padding:0px;
margin: 0 auto;
}
</style>
<script>
function show(e){
e = e || event;
if(e.stopPropogation){
alert(1);
e.stopPropogation();
}else{
e.cancelBubble = true;
}
document.getElementById("content1").style.display = "";
}
function init(){
document.body.onmousedown = function(){
document.getElementById("content1").style.display = "none";
};
}
</script>
</head>
<body onload="init()">
<input type="button" value="显示" onclick="show(event)"/>
<div id="content1" style="display:none">
关注排行
1. 关注排行1
2. 关注排行2
3. 关注排行3
4. 关注排行4
</div>
</body>
</html>
$("div [id=a]").hide();显示用show()
<head>
<title>test</title>
<script type="text/javascript">
function show(oEvent){
document.getElementById("a").style.display = "block";
e = window.event || oEvent;
if (e.stopPropagation)
{
e.stopPropagation();
}else{
e.cancelBubble = true;
}
}
function hide(){
document.getElementById("a").style.display = "none";
}
</script>
</head>
<body onclick="hide();">
<input type="button" onclick = "show();" />
<div id="a">
test
</div>
</body>
</html>
<html>
<head>
<title>test</title>
<script type="text/javascript">
function show(oEvent){
document.getElementById("a").style.display = "block";
e = window.event || oEvent;
if (e.stopPropagation)
{
e.stopPropagation();
}else{
e.cancelBubble = true;
}
}
function hide(){
document.getElementById("a").style.display = "none";
}
window.onload = function(){
document.body.onclick = hide;
document.getElementById("c").onclick = show;
};
</script>
</head>
<body>
<input id="c" type="button" value="ClickMe" />
<div id="a">
test
</div>
</body>
</html>