function cls(sobj)
{
var obj = document.getElementById(sobj);
obj.parentNode.removeChild(obj);
//or obj.style.display = "none";}
{
var obj = document.getElementById(sobj);
obj.parentNode.removeChild(obj);
//or obj.style.display = "none";}
{ var win = obj.parentNode.parentNode;
var sha = win.nextSibling;
win.style.visibility = "hidden";
sha.style.visibility = "hidden";
}
就是那个参数 obj 我在鼠标事件中怎么得到如下:
<a href="#" onmouseout=cls('???????')> 传什么?</a> 要传div 的this 指针,可是要怎么得到呢?
实现设置的
<a href="#" onmouseout=cls(这里写你要关闭层的id)>
然后你的JS里有程序获取该ID执行相关事件
函数里是这样关闭的: 下面的代码就是上面的 function bulid()函数里的.
+ "ondblclick='min(this.childNodes[1])'"
+ "> "
+ " <span style='width:" + (this.width-2*12-4) + ";padding- left:3px;'> " + this.title + " </span> "
+ " <span style='width:12;border-width:0px;color:white;font- family:webdings;' onclick='min(this)'> 0 </span> "
+ " <span style='width:12;border-width:0px;color:white;font- family:webdings;' onclick='cls(this)'> r </span> " //在这里关闭
+ " </div> " 但是我想用在一个超链接的鼠标onmouseout事件中关闭那个层.
那你的程序是怎么写的关闭??????
代码里有获得ID的相关程序吗?
我现在想放到body里和onmouseout事件.function bulid() 函数在我上面发贴里有.
{ //var win = obj.parentNode.parentNode;
var win=document.getElementById(obj);
var sha = win.nextSibling;
win.style.visibility = "hidden";
//sha.style.visibility = "hidden";
}
<div id="xMsg">sfsf</div>
测试一下就知道了
function cls(obj)
{ //var win = obj.parentNode.parentNode;
var win=document.getElementById(obj);
var sha = win.nextSibling;
win.style.visibility = "hidden";
//sha.style.visibility = "hidden";
}
</script><div id="xMsg"> sfsf </div>
<a href="#" onMouseOut="cls('xMsg')")>关闭 </a>
你直接复制这个去测试就知道了
我只要知道你的层ID就行
你移动去哪ID都不会变吧??
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网页特效|Linkweb.cn/Js|---页面内的超级酷浮动窗口</title>
<style type='text/css'>
<!--
a:visited{text-decoration:none;color:slategray;}
a:hover{text-decoration:underline;color:slategray;}
a:link{text-decoration:none;color:slategray;}
-->
</style>
<script language=JScript>
<!--
//可以打包为js文件;
var x0=0,y0=0,x1=0,y1=0;
var offx=6,offy=6;
var moveable=false;
var hover='orange',normal='slategray';//color;
var index=10000;//z-index;
//开始拖动;
function startDrag(obj)
{
if(event.button==1)
{
//锁定标题栏;
obj.setCapture();
//定义对象;
var win = obj.parentNode;
var sha = win.nextSibling;
//记录鼠标和层位置;
x0 = event.clientX;
y0 = event.clientY;
x1 = parseInt(win.style.left);
y1 = parseInt(win.style.top);
//记录颜色;
normal = obj.style.backgroundColor;
//改变风格;
obj.style.backgroundColor = hover;
win.style.borderColor = hover;
obj.nextSibling.style.color = hover;
sha.style.left = x1 + offx;
sha.style.top = y1 + offy;
moveable = true;
}
}
//拖动;
function drag(obj)
{
if(moveable)
{
var win = obj.parentNode;
var sha = win.nextSibling;
win.style.left = x1 + event.clientX - x0;
win.style.top = y1 + event.clientY - y0;
sha.style.left = parseInt(win.style.left) + offx;
sha.style.top = parseInt(win.style.top) + offy;
}
}
//停止拖动;
function stopDrag(obj)
{
if(moveable)
{
var win = obj.parentNode;
var sha = win.nextSibling;
var msg = obj.nextSibling;
win.style.borderColor = normal;
obj.style.backgroundColor = normal;
msg.style.color = normal;
win.style.left = x1 + event.clientX - x0;
win.style.top = y1 + event.clientY - y0;
sha.style.left = parseInt(win.style.left) + offx;
sha.style.top = parseInt(win.style.top) + offy;
obj.releaseCapture();
moveable = false;
}
}
//获得焦点;
function getFocus(obj)
{
if(obj.style.zIndex!=index)
{
index = index + 2;
var idx = index;
obj.style.zIndex=idx;
obj.nextSibling.style.zIndex=idx-1;
}
}
//最小化;
function min(obj)
{
var win = obj.parentNode.parentNode;
var sha = win.nextSibling;
var tit = obj.parentNode;
var msg = tit.nextSibling;
var flg = msg.style.display=="none";
if(flg)
{
win.style.height = parseInt(msg.style.height) + parseInt(tit.style.height) + 2*2;
sha.style.height = win.style.height;
msg.style.display = "block";
obj.innerHTML = "0";
}
else
{
win.style.height = parseInt(tit.style.height) + 2*2;
sha.style.height = win.style.height;
obj.innerHTML = "2";
msg.style.display = "none";
}
}
//关闭;
function cls(obj)
{
var win = obj.parentNode.parentNode;
var sha = win.nextSibling;
win.style.visibility = "hidden";
sha.style.visibility = "hidden";
}
//创建一个对象;
function xWin(id,w,h,l,t,tit,msg)
{
index = index+2;
this.id = id;
this.width = w;
this.height = h;
this.left = l;
this.top = t;
this.zIndex = index;
this.title = tit;
this.message = msg;
this.obj = null;
this.bulid = bulid;
this.bulid();
}
//初始化;
function bulid()
{
var str = ""
+ "<div id=xMsg" + this.id + " "
+ "style='"
+ "z-index:" + this.zIndex + ";"
+ "width:" + this.width + ";"
+ "height:" + this.height + ";"
+ "left:" + this.left + ";"
+ "top:" + this.top + ";"
+ "background-color:" + normal + ";"
+ "color:" + normal + ";"
+ "font-size:11px;"
+ "font-family:Verdana;"
+ "position:absolute;"
+ "cursor:default;"
+ "border:2px solid " + normal + ";"
+ "' "
+ "onmousedown='getFocus(this)'>"
+ "<div "
+ "style='"
+ "background-color:" + normal + ";"
+ "width:" + (this.width-2*2) + ";"
+ "height:20;"
+ "color:white;"
+ "' "
+ "onmousedown='startDrag(this)' "
+ "onmouseup='stopDrag(this)' "
+ "onmousemove='drag(this)' "
+ "ondblclick='min(this.childNodes[1])'"
+ ">"
+ "<span style='width:" + (this.width-2*12-4) + ";padding-left:3px;'>" + this.title + "</span>"
+ "<span style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='min(this)'>0</span>"
+ "<span style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='cls(this)'>r</span>"
+ "</div>"
+ "<div style='"
+ "width:100%;"
+ "height:" + (this.height-20-4) + ";"
+ "background-color:white;"
+ "line-height:14px;"
+ "word-break:break-all;"
+ "padding:3px;"
+ "'>" + this.message + "</div>"
+ "</div>"
+ "<div style='"
+ "width:" + this.width + ";"
+ "height:" + this.height + ";"
+ "top:" + this.top + ";"
+ "left:" + this.left + ";"
+ "z-index:" + (this.zIndex-1) + ";"
+ "position:absolute;"
+ "background-color:black;"
+ "filter:alpha(opacity=40);"
+ "'>by wildwind</div>";
document.body.insertAdjacentHTML("beforeEnd",str);
}
//-->
</script><script language='JScript'>
<!--
function initialize()
{
var b = new xWin("2",240,200,100,100,"班员信息","Welcome to visited my personal website:<br><a href=http://www14.brinkster.com/wildcity target=_blank>http://wildcity.126.com</a><br>and u can also sign my guestbook at:<br><a href=http://www14.brinkster.com/wildcity/gbook target=_blank>http://wildcity.126.com/gbook</a><br><br>thx!!! =)...");}
//window.onload = initialize;
//-->
</script>
</head>
<body onselectstart='return false' scroll='no'>
<a href="#" onmouseover=initialize() onmouseout="cls('xMsg')">test</a>
<div id="xMsg"> sfsf </div> <br>
</body>
</html>
再说你的ID也不对!!<div id=xMsg" + this.id + " "
有这么写的吗?
你这么写ID都不知道啥了
去掉<div id=xMsg" + " " 后可以关闭一次,但并不是完全关闭,说明你里面有多层干扰,ID也不稳定
你自己看是不是我的
只能关闭一次
具体的我也不知道你的是怎么写的了
一关闭所有都关闭了
给这个加上一个ID<a href="#" onmouseover=initialize() onmouseout="cls(document.getElementById('xMsg'))"> test </a>
使用这样就完全可以关闭一次
但是第二次无法关闭
我懒得看那密密麻麻的
你自己看吧