如何显示和隐藏层,谢谢各位? 有一层 DIV ID=MYCRM 有一按钮: ID=myinfo 要实现: 当点击按钮,层显示,并且可以操作层里面的相关链接。当鼠标移开层后,层自动隐藏。 谢谢各位了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 getElementById('div').style.display='hidden' //隐藏getElementById('div').style.display='block' //打开 有一层 DIV ID=MYCRM 有一按钮: ID=myinfo 要实现: 当点击按钮,层显示,并且可以操作层里面的相关按钮。当鼠标移开层后,层自动隐藏。 谢谢各位了 当点击时document.getElementById('id').style.display="";当鼠标离开时:$("#id").bind("mouseleave", function(){ menu = document.all.itemopen//itemopen是id menu.style.display = "none" }); <button id='btn1' .... /><script type='text/javascript'>document.getElementById('btn1').onclick=function(){ getElementById('div').style.display='block'; //你要显示的层div} 楼上的两位 误解楼主了.. 你们没注意 主要的问题是.. 鼠标移开DIV隐藏 但可以点击链接这个方面这才是主要 呵呵 <!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></head><body><div id="MYCRM" style="display:none;width:100px;height:100px;border:1px solid #ddd;">this is a layer</div><input type="button" id="myinfo" value="myinfo" /><script type="text/javascript">document.getElementById('myinfo').onclick=function(){ var tm=document.getElementById('MYCRM'); tm.style.display='block'; tm.onmouseout=function(){ this.style.display='none'; }} </script></body></html> 用了。鼠标移到DIV上就消失了。DIV里面有按钮事件,用ONBLUR也不行 <div id="MYCRM" style="width: 300px; height: 200px; background-color:#E6E6E6; display:none"> <a href='http://www.baidu.com'>Baidu</a></div><input type="button" id="myinfo" value="ShowInfo" /><script type="text/javascript">(function(){ var contains = function(a, b) { return a.contains ? a != b && a.contains(b) : !!(a.compareDocumentPositon(b) & 16); } function Event(e){ var oEvent = document.all ? window.event : e; if (document.all) { if(oEvent.type == "mouseout") { oEvent.relatedTarget = oEvent.toElement; }else if(oEvent.type == "mouseover") { oEvent.relatedTarget = oEvent.fromElement; } } return oEvent; } var btn = document.getElementById('myinfo'); var div = document.getElementById('MYCRM'); btn.onclick = function(){ div.onmouseout = function(event){ var target = Event(event).relatedTarget; if(!contains(this, target)){ this.style.display = 'none'; this.onmouseout = null; }else { target.onmouseout = function(event) { event = event || window.event; if(event.stopPropagation) { event.stopPropagation(); }else { event.cancelBubble = true; } } } } div.style.display = 'block'; }})();</script> (学而不思则罔) 的代码刚才试过了。可以,就是感觉代码有点多,t6new.cn) 刚才试过了。如果我在DIV里面加入一些按钮什么的,就不行了。感谢大家 <div id="MYCRM" style="width: 300px; height: 200px; background-color:#E6E6E6; display:none"> <a href='http://www.baidu.com'>Baidu</a> <button type="button">测试</button></div><input type="button" id="myinfo" value="ShowInfo" />(function() { var btn = document.getElementById('myinfo'); var div = document.getElementById('MYCRM'); btn.onclick = function() { div.style.display = ''; div.onmouseout = function(e) { e = e || window.event; var target = e.srcElement ? e.srcElement : e.target, related = e.toElement ? e.toElement : e.relatedTarget; if (!div.contains(related)) div.style.display = 'none'; } } })(); getElementById('div').style.display='hidden' //隐藏 这个写错了。应该是:getElementById('div').style.display='none' //隐藏 <div id=div style="width:200;height:100;background:gray;visibility:hidden" onmouseout={this.style.visibility="hidden"}><a href="" onmouseover={div.style.visibility=""}>111</a><br><a href="" onmouseover={div.style.visibility=""}>222</a></div><input type=submit value="ok" onclick={div.style.visibility=""}> jquery字符串问题 extjs的问题 急!!!!! 动态创建表格问题! javascript基础东东,请教下。 跟数据库连接起来,生成动态树状菜单的问题~~,问题解决马上给分~~ 第三次发贴了 高分相送~!各位大哥哥大姐姐,帮帮忙看看怎么把我的二级菜单改成三级的~! 如何控制iframe中的指向 请问JavaScript可以对本地的数据库进行操作么?比如:查询,插入,修改等 请教下javascript里var新建的复杂对象变量有办法挂载事件吗? javascript正则表达式 Function和function区别在哪
getElementById('div').style.display='block' //打开
有一按钮: ID=myinfo
要实现:
当点击按钮,层显示,并且可以操作层里面的相关按钮。当鼠标移开层后,层自动隐藏。
谢谢各位了
当鼠标离开时:$("#id").bind("mouseleave", function(){
menu = document.all.itemopen//itemopen是id
menu.style.display = "none"
});
<script type='text/javascript'>
document.getElementById('btn1').onclick=function(){ getElementById('div').style.display='block'; //你要显示的层div
}
楼上的两位 误解楼主了.. 你们没注意 主要的问题是.. 鼠标移开DIV隐藏 但可以点击链接这个方面
这才是主要 呵呵
<!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>
</head><body>
<div id="MYCRM" style="display:none;width:100px;height:100px;border:1px solid #ddd;">
this is a layer</div>
<input type="button" id="myinfo" value="myinfo" />
<script type="text/javascript">
document.getElementById('myinfo').onclick=function(){
var tm=document.getElementById('MYCRM');
tm.style.display='block';
tm.onmouseout=function(){
this.style.display='none';
}
} </script>
</body>
</html>
<div id="MYCRM" style="width: 300px; height: 200px; background-color:#E6E6E6; display:none">
<a href='http://www.baidu.com'>Baidu</a>
</div>
<input type="button" id="myinfo" value="ShowInfo" />
<script type="text/javascript">
(function(){
var contains = function(a, b) {
return a.contains ? a != b && a.contains(b) : !!(a.compareDocumentPositon(b) & 16);
}
function Event(e){
var oEvent = document.all ? window.event : e;
if (document.all) {
if(oEvent.type == "mouseout") {
oEvent.relatedTarget = oEvent.toElement;
}else if(oEvent.type == "mouseover") {
oEvent.relatedTarget = oEvent.fromElement;
}
}
return oEvent;
}
var btn = document.getElementById('myinfo');
var div = document.getElementById('MYCRM');
btn.onclick = function(){
div.onmouseout = function(event){
var target = Event(event).relatedTarget;
if(!contains(this, target)){
this.style.display = 'none';
this.onmouseout = null;
}else {
target.onmouseout = function(event) {
event = event || window.event;
if(event.stopPropagation) {
event.stopPropagation();
}else {
event.cancelBubble = true;
}
}
}
}
div.style.display = 'block';
}})();
</script>
t6new.cn) 刚才试过了。如果我在DIV里面加入一些按钮什么的,就不行了。
感谢大家
<div id="MYCRM" style="width: 300px; height: 200px; background-color:#E6E6E6; display:none">
<a href='http://www.baidu.com'>Baidu</a>
<button type="button">测试</button>
</div>
<input type="button" id="myinfo" value="ShowInfo" />(function() {
var btn = document.getElementById('myinfo');
var div = document.getElementById('MYCRM');
btn.onclick = function() {
div.style.display = '';
div.onmouseout = function(e) {
e = e || window.event;
var target = e.srcElement ? e.srcElement : e.target,
related = e.toElement ? e.toElement : e.relatedTarget;
if (!div.contains(related)) div.style.display = 'none';
}
}
})();
这个写错了。应该是:
getElementById('div').style.display='none' //隐藏
<a href="" onmouseover={div.style.visibility=""}>111</a><br>
<a href="" onmouseover={div.style.visibility=""}>222</a></div>
<input type=submit value="ok" onclick={div.style.visibility=""}>