关于一个js在FF和IE下兼容的问题 其实这个例子本来是IE下的代码,没有一点问题。但是放在FF下不知道有多少问题,然我改了下,发现还有好多问题。一个是样式,还有就是在FF下拖动的问题,一快了,他就有时候就不动了。在IE下没问题。谁帮我改下兼容FF,然后在改的地方写下注释,我100分都奉上 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script type="text/javascript" language="JScript"> //可以打包为js文件; var x0 = 0, y0 = 0, x1 = 0, y1 = 0; var offx = 6, offy = 6; var moveable = false; var hover = 'orange', normal = '#336699'; //color; var index = 10000; //z-index; //开始拖动; function startDrag(obj, event) { //alert(event.button) // if (event.button == 1 || event.button == 0) // { //锁定标题栏; //obj.setCapture(); /*抓取事件*/ if (!window.captureEvents) obj.setCapture(); else window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP); //定义对象; 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, event) { if (moveable) { var win = obj.parentNode; var sha = win.nextSibling; //document.getElementById('abc').innerHTML += "," + win.nextSibling.style.top; 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; sha.style.left = obj.parentNode.style.left; sha.style.top = obj.parentNode.style.top; //obj.releaseCapture(); if (!window.captureEvents) obj.releaseCapture(); else window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP); 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 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:8pt;"+ "font-family:Tahoma;"+ "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,event)' "+ "onmouseup='stopDrag(this)' "+ "onmousemove='drag(this,event)' "+ "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='ShowHide(\"" + this.id + "\",null)'>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 id=xMsg" + this.id + "bg 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);"+ "'></div>"; //document.body.insertAdjacentHTML("beforeEnd", str); document.body.innerHTML += str; } //显示隐藏窗口 function ShowHide(id, dis) { var bdisplay = (dis == null) ? ((document.getElementById("xMsg" + id).style.display == "") ? "none" : "") : dis document.getElementById("xMsg" + id).style.display = bdisplay; document.getElementById("xMsg" + id + "bg").style.display = bdisplay; } //--></script><script language="javascript"> function initialize() { var a = new xWin("1", 160, 200, 200, 200, "窗口1", "xWin A Cool Pop Div WindowXueMu.Net2006-5-13"); var b = new xWin("2", 240, 200, 100, 100, "窗口2", "Welcome to visited my personal website:<a href=http://www.xuemu.net target=_blank>http://www.xuemu.net</a>请多提建议噢感谢您的关注!"); var c = new xWin("3", 200, 160, 250, 50, "窗口3", "Copyright by <a href='#'>Wildwind</a>!"); ShowHide("1", "none"); //隐藏窗口1 } window.onload = initialize;</script><base target="_blank"><a onclick="ShowHide('1',null);return false;" href="">窗口1</a> <a onclick="ShowHide('2',null);return false;" href="">窗口2</a> <a onclick="ShowHide('3',null);return false;" href="">窗口3</a><p> <div id="abc"> </div> 查找更多代码,请访问:<a href="http://www.lanrentuku.com" target="_blank">懒人图库</a></p> obj.style.pixelLeft的问题if(navigator.appName.indexOf("Explorer") > -1){//IE obj.style.pixelLeft = newX+8; obj.style.pixelTop = newY-5; }else{ obj.style.left = parseInt(newX)-155+"px";//Firefox对"px"要求严格 obj.style.top = parseInt(newY)-135+"px"; } 事件源的问题:function startDrag(obj, eve){evt = evt ? evt : (window.event ? window.event : null);...} 你没用w3c的标准写js一会我写下传上来 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <script type="text/javascript" language="JScript"> //可以打包为js文件; var x_open_ie5 = document.all && document.getElementById; var x_open_ns6 = document.getElementById && !document.all; var x0 = 0, y0 = 0, x1 = 0, y1 = 0; var offx = 6, offy = 6; var moveable = false; var hover = 'orange', normal = '#336699'; //color; var index = 10000; //z-index; //开始拖动; function startDrag(obj, event) { drag(this,event); stopDrag(this); //定义对象; 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, e) { if (moveable) {2010-1-14 var evt = x_open_ns6 ? e : event; var win = obj.parentNode; var sha = win.nextSibling; win.style.left = x1 + evt.clientX - x0; win.style.top = y1 + evt.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; sha.style.left = obj.parentNode.style.left; sha.style.top = obj.parentNode.style.top; 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 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:8pt;"+ "font-family:Tahoma;"+ "position:absolute;"+ "cursor:default;"+ "border:2px solid " + normal + ";"+ "' "+ "onmousedown='getFocus(this)'>"+ "<div id=d1 "+ "style='"+ "background-color:" + normal + ";"+ "width:" + (this.width - 2 * 2) + ";"+ "height:20;"+ "color:white;"+ "' "+ "onmousedown='startDrag(this,event)' "+ "onmouseup='stopDrag(this)' "+ "onmousemove='drag(this,event)' "+ "ondblclick='min(this.childNodes[1])'"+ ">"+ "<span id=s1 style='width:" + (this.width - 2 * 12 - 4) + ";'>" + this.title + "</span>"+ "<span id=s2 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='min(this)'></span>"+ "<span id=s3 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='ShowHide(\"" + this.id + "\",null)'>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 id=xMsg" + this.id + "bg 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);"+ "'></div>"; document.body.innerHTML += str; var s1=document.getElementById("s1"); //s1.setAttribute("width",(this.width - 2 * 12 - 4)); s1.style.width=(this.width - 2 * 12 - 4); //alert(s1.style.width) s1.style.paddingLeft="3px"; var s2=document.getElementById("s2"); s2.style.fontFamily="webdings"; s2.innerHTML="0" var s3=document.getElementById("s3"); s3.style.fontFamily="webdings"; s3.innerHTML="r" } //显示隐藏窗口 function ShowHide(id, dis) { var bdisplay = (dis == null) ? ((document.getElementById("xMsg" + id).style.display == "") ? "none" : "") : dis document.getElementById("xMsg" + id).style.display = bdisplay; document.getElementById("xMsg" + id + "bg").style.display = bdisplay; } //--></script><script language="javascript"> function initialize() { var a = new xWin("1", 160, 200, 200, 200, "窗口1", "xWin A Cool Pop Div WindowXueMu.Net2006-5-13"); var b = new xWin("2", 240, 200, 100, 100, "窗口2", "Welcome to visited my personal website:<a href=http://www.xuemu.net target=_blank>http://www.xuemu.net</a>请多提建议噢感谢您的关注!"); var c = new xWin("3", 200, 160, 250, 50, "窗口3", "Copyright by <a href='#'>Wildwind</a>!"); ShowHide("1", "none"); //隐藏窗口1 } window.onload = initialize;</script><base target="_blank"><a onclick="ShowHide('1',null);return false;" href="">窗口1</a> <a onclick="ShowHide('2',null);return false;" href="">窗口2</a> <a onclick="ShowHide('3',null);return false;" href="">窗口3</a><p> <div id="abc"> </div> 查找更多代码,请访问:<a href="http://www.lanrentuku.com" target="_blank">懒人图库</a></p></HTML>------------------------------------------------不好意思啊。昨天临时有事代码如上,我稍微做了一点改动,解决了captureEvents 在火狐里面过时的错误。。但是你的样式不显示我解决不了,因为火狐里面不支持font-family:webdings 字体。我建议你把 最小化最大化和关闭按钮做成图片,这样更美观,也不会出现这种问题了 没有错误啊。。我拿你的在ie里面没有拖动没有错误。。在火狐里面拖动有错误。。我现在的在ie火狐里面都没有错误啊。。还要说下,我的是ie6 不好意思,发错代码了刚刚发的是之前改的没有错误的在下面-----------------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <script type="text/javascript" language="JScript"> //可以打包为js文件; var x_open_ie5 = document.all && document.getElementById; var x_open_ns6 = document.getElementById && !document.all; var x0 = 0, y0 = 0, x1 = 0, y1 = 0; var offx = 6, offy = 6; var moveable = false; var hover = 'orange', normal = '#336699'; //color; var index = 10000; //z-index; //开始拖动; function startDrag(obj, event) { drag(this,event); stopDrag(this); //定义对象; 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, e) { if (moveable) {2010-1-14 var evt = x_open_ns6 ? e : event; var win = obj.parentNode; var sha = win.nextSibling; win.style.left = x1 + evt.clientX - x0; win.style.top = y1 + evt.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; sha.style.left = obj.parentNode.style.left; sha.style.top = obj.parentNode.style.top; 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 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:8pt;"+ "font-family:Tahoma;"+ "position:absolute;"+ "cursor:default;"+ "border:2px solid " + normal + ";"+ "' "+ "onmousedown='getFocus(this)'>"+ "<div id=d1 "+ "style='"+ "background-color:" + normal + ";"+ "width:" + (this.width - 2 * 2) + ";"+ "height:20;"+ "color:white;"+ "' "+ "onmousedown='startDrag(this,event)' "+ "onmouseup='stopDrag(this)' "+ "onmousemove='drag(this,event)' "+ "ondblclick='min(this.childNodes[1])'"+ ">"+ "<span id=s1 style='width:" + (this.width - 2 * 12 - 4) + ";'>" + this.title + "</span>"+ "<span id=s2 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='min(this)'></span>"+ "<span id=s3 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='ShowHide(\"" + this.id + "\",null)'>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 id=xMsg" + this.id + "bg 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);"+ "'></div>"; document.body.innerHTML += str; var s1=document.getElementById("s1"); //s1.setAttribute("width",(this.width - 2 * 12 - 4)); s1.style.width=(this.width - 2 * 12 - 4); //alert(s1.style.width) s1.style.paddingLeft="3px"; var s2=document.getElementById("s2"); s2.style.fontFamily="webdings"; s2.innerHTML="0" var s3=document.getElementById("s3"); s3.style.fontFamily="webdings"; s3.innerHTML="r" } //显示隐藏窗口 function ShowHide(id, dis) { var bdisplay = (dis == null) ? ((document.getElementById("xMsg" + id).style.display == "") ? "none" : "") : dis document.getElementById("xMsg" + id).style.display = bdisplay; document.getElementById("xMsg" + id + "bg").style.display = bdisplay; } //--></script><script language="javascript"> function initialize() { var a = new xWin("1", 160, 200, 200, 200, "窗口1", "xWin A Cool Pop Div WindowXueMu.Net2006-5-13"); var b = new xWin("2", 240, 200, 100, 100, "窗口2", "Welcome to visited my personal website:<a href=http://www.xuemu.net target=_blank>http://www.xuemu.net</a>请多提建议噢感谢您的关注!"); var c = new xWin("3", 200, 160, 250, 50, "窗口3", "Copyright by <a href='#'>Wildwind</a>!"); ShowHide("1", "none"); //隐藏窗口1 } window.onload = initialize;</script><base target="_blank"><a onclick="ShowHide('1',null);return false;" href="">窗口1</a> <a onclick="ShowHide('2',null);return false;" href="">窗口2</a> <a onclick="ShowHide('3',null);return false;" href="">窗口3</a><p> <div id="abc"> </div> 查找更多代码,请访问:<a href="http://www.lanrentuku.com" target="_blank">懒人图库</a></p></HTML> 是这个-----------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <script type="text/javascript" language="JScript"> //可以打包为js文件; var x_open_ie5 = document.all && document.getElementById; var x_open_ns6 = document.getElementById && !document.all; var x0 = 0, y0 = 0, x1 = 0, y1 = 0; var offx = 6, offy = 6; var moveable = false; var hover = 'orange', normal = '#336699'; //color; var index = 10000; //z-index; //开始拖动; function startDrag(obj, event) { drag(this,event); stopDrag(this); //定义对象; 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, e) { if (moveable) {2010-1-14 var evt = x_open_ns6 ? e : event; var win = obj.parentNode; var sha = win.nextSibling; win.style.left = x1 + evt.clientX - x0; win.style.top = y1 + evt.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; sha.style.left = obj.parentNode.style.left; sha.style.top = obj.parentNode.style.top; 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 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:8pt;"+ "font-family:Tahoma;"+ "position:absolute;"+ "cursor:default;"+ "border:2px solid " + normal + ";"+ "' "+ "onmousedown='getFocus(this)'>"+ "<div id=d1 "+ "style='"+ "background-color:" + normal + ";"+ "width:" + (this.width - 2 * 2) + ";"+ "height:20;"+ "color:white;"+ "' "+ "onmousedown='startDrag(this,event)' "+ "onmouseup='stopDrag(this)' "+ "onmousemove='drag(this,event)' "+ "ondblclick='min(this.childNodes[1])'"+ ">"+ "<span id=s1 style='width:" + (this.width - 2 * 12 - 4) + ";'>" + this.title + "</span>"+ "<span id=s2 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='min(this)'></span>"+ "<span id=s3 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='ShowHide(\"" + this.id + "\",null)'>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 id=xMsg" + this.id + "bg 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);"+ "'></div>"; document.body.innerHTML += str; var s1=document.getElementById("s1"); //s1.setAttribute("width",(this.width - 2 * 12 - 4)); s1.style.width=(this.width - 2 * 12 - 4); //alert(s1.style.width) s1.style.paddingLeft="3px"; var s2=document.getElementById("s2"); s2.style.fontFamily="webdings"; s2.innerHTML="0" var s3=document.getElementById("s3"); s3.style.fontFamily="webdings"; s3.innerHTML="r" } //显示隐藏窗口 function ShowHide(id, dis) { var bdisplay = (dis == null) ? ((document.getElementById("xMsg" + id).style.display == "") ? "none" : "") : dis document.getElementById("xMsg" + id).style.display = bdisplay; document.getElementById("xMsg" + id + "bg").style.display = bdisplay; } //--></script><script language="javascript"> function initialize() { var a = new xWin("1", 160, 200, 200, 200, "窗口1", "xWin A Cool Pop Div WindowXueMu.Net2006-5-13"); var b = new xWin("2", 240, 200, 100, 100, "窗口2", "Welcome to visited my personal website:<a href=http://www.xuemu.net target=_blank>http://www.xuemu.net</a>请多提建议噢感谢您的关注!"); var c = new xWin("3", 200, 160, 250, 50, "窗口3", "Copyright by <a href='#'>Wildwind</a>!"); ShowHide("1", "none"); //隐藏窗口1 } window.onload = initialize;</script><base target="_blank"><a onclick="ShowHide('1',null);return false;" href="">窗口1</a> <a onclick="ShowHide('2',null);return false;" href="">窗口2</a> <a onclick="ShowHide('3',null);return false;" href="">窗口3</a><p> <div id="abc"> </div> 查找更多代码,请访问:<a href="http://www.lanrentuku.com" target="_blank">懒人图库</a></p></HTML> 懂正则表达式的请进 关于JQUERY的问题,不能得到值,求解! 关于在线编辑器的问题,怎样获得选中文字并进行处理 如何给web聊天室的发送按钮配置快捷键 奇怪的100% ul 宽度 请大家无论如何帮我这个忙,谢谢 了. 如何屏蔽IE的后退和前进按钮 请教 十万火急!!!! 我用模态窗口打开一个日历控件窗口为什么打开后十分慢?? 请教:如何封锁浏览器,既让网页让的任何控件都得不到焦点?先谢谢了。 这段JS为什么能在FireFox运行,但是不能再IE6中运行? 如何用javascript根据事件改变style?
//可以打包为js文件;
var x0 = 0, y0 = 0, x1 = 0, y1 = 0;
var offx = 6, offy = 6;
var moveable = false;
var hover = 'orange', normal = '#336699'; //color;
var index = 10000; //z-index;
//开始拖动;
function startDrag(obj, event)
{
//alert(event.button)
// if (event.button == 1 || event.button == 0)
// {
//锁定标题栏;
//obj.setCapture();
/*抓取事件*/
if (!window.captureEvents)
obj.setCapture();
else
window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
//定义对象;
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, event)
{
if (moveable)
{
var win = obj.parentNode;
var sha = win.nextSibling;
//document.getElementById('abc').innerHTML += "," + win.nextSibling.style.top;
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;
sha.style.left = obj.parentNode.style.left;
sha.style.top = obj.parentNode.style.top;
//obj.releaseCapture();
if (!window.captureEvents)
obj.releaseCapture();
else
window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);
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 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:8pt;"
+ "font-family:Tahoma;"
+ "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,event)' "
+ "onmouseup='stopDrag(this)' "
+ "onmousemove='drag(this,event)' "
+ "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='ShowHide(\"" + this.id + "\",null)'>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 id=xMsg" + this.id + "bg 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);"
+ "'></div>"; //document.body.insertAdjacentHTML("beforeEnd", str);
document.body.innerHTML += str;
}
//显示隐藏窗口
function ShowHide(id, dis)
{
var bdisplay = (dis == null) ? ((document.getElementById("xMsg" + id).style.display == "") ? "none" : "") : dis
document.getElementById("xMsg" + id).style.display = bdisplay;
document.getElementById("xMsg" + id + "bg").style.display = bdisplay;
}
//-->
</script><script language="javascript">
function initialize()
{
var a = new xWin("1", 160, 200, 200, 200, "窗口1", "xWin A Cool Pop Div WindowXueMu.Net2006-5-13");
var b = new xWin("2", 240, 200, 100, 100, "窗口2", "Welcome to visited my personal website:<a href=http://www.xuemu.net target=_blank>http://www.xuemu.net</a>请多提建议噢感谢您的关注!");
var c = new xWin("3", 200, 160, 250, 50, "窗口3", "Copyright by <a href='#'>Wildwind</a>!");
ShowHide("1", "none"); //隐藏窗口1
}
window.onload = initialize;
</script><base target="_blank">
<a onclick="ShowHide('1',null);return false;" href="">窗口1</a> <a onclick="ShowHide('2',null);return false;"
href="">窗口2</a> <a onclick="ShowHide('3',null);return false;" href="">窗口3</a>
<p>
<div id="abc">
</div>
查找更多代码,请访问:<a href="http://www.lanrentuku.com" target="_blank">懒人图库</a></p>
if(navigator.appName.indexOf("Explorer") > -1){//IE
obj.style.pixelLeft = newX+8;
obj.style.pixelTop = newY-5;
}else{
obj.style.left = parseInt(newX)-155+"px";//Firefox对"px"要求严格
obj.style.top = parseInt(newY)-135+"px";
}
function startDrag(obj, eve){
evt = evt ? evt : (window.event ? window.event : null);
...
}
一会我写下传上来
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <script type="text/javascript" language="JScript">
//可以打包为js文件;
var x_open_ie5 = document.all && document.getElementById;
var x_open_ns6 = document.getElementById && !document.all;
var x0 = 0, y0 = 0, x1 = 0, y1 = 0;
var offx = 6, offy = 6;
var moveable = false;
var hover = 'orange', normal = '#336699'; //color;
var index = 10000; //z-index;
//开始拖动;
function startDrag(obj, event)
{
drag(this,event);
stopDrag(this);
//定义对象;
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, e)
{
if (moveable)
{2010-1-14
var evt = x_open_ns6 ? e : event;
var win = obj.parentNode;
var sha = win.nextSibling;
win.style.left = x1 + evt.clientX - x0;
win.style.top = y1 + evt.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;
sha.style.left = obj.parentNode.style.left;
sha.style.top = obj.parentNode.style.top;
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 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:8pt;"
+ "font-family:Tahoma;"
+ "position:absolute;"
+ "cursor:default;"
+ "border:2px solid " + normal + ";"
+ "' "
+ "onmousedown='getFocus(this)'>"
+ "<div id=d1 "
+ "style='"
+ "background-color:" + normal + ";"
+ "width:" + (this.width - 2 * 2) + ";"
+ "height:20;"
+ "color:white;"
+ "' "
+ "onmousedown='startDrag(this,event)' "
+ "onmouseup='stopDrag(this)' "
+ "onmousemove='drag(this,event)' "
+ "ondblclick='min(this.childNodes[1])'"
+ ">"
+ "<span id=s1 style='width:" + (this.width - 2 * 12 - 4) + ";'>" + this.title + "</span>"
+ "<span id=s2 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='min(this)'></span>"
+ "<span id=s3 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='ShowHide(\"" + this.id + "\",null)'>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 id=xMsg" + this.id + "bg 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);"
+ "'></div>";
document.body.innerHTML += str;
var s1=document.getElementById("s1");
//s1.setAttribute("width",(this.width - 2 * 12 - 4));
s1.style.width=(this.width - 2 * 12 - 4);
//alert(s1.style.width)
s1.style.paddingLeft="3px"; var s2=document.getElementById("s2");
s2.style.fontFamily="webdings";
s2.innerHTML="0"
var s3=document.getElementById("s3");
s3.style.fontFamily="webdings";
s3.innerHTML="r"
}
//显示隐藏窗口
function ShowHide(id, dis)
{
var bdisplay = (dis == null) ? ((document.getElementById("xMsg" + id).style.display == "") ? "none" : "") : dis
document.getElementById("xMsg" + id).style.display = bdisplay;
document.getElementById("xMsg" + id + "bg").style.display = bdisplay;
}
//-->
</script><script language="javascript">
function initialize()
{
var a = new xWin("1", 160, 200, 200, 200, "窗口1", "xWin A Cool Pop Div WindowXueMu.Net2006-5-13");
var b = new xWin("2", 240, 200, 100, 100, "窗口2", "Welcome to visited my personal website:<a href=http://www.xuemu.net target=_blank>http://www.xuemu.net</a>请多提建议噢感谢您的关注!");
var c = new xWin("3", 200, 160, 250, 50, "窗口3", "Copyright by <a href='#'>Wildwind</a>!");
ShowHide("1", "none"); //隐藏窗口1
}
window.onload = initialize;
</script><base target="_blank">
<a onclick="ShowHide('1',null);return false;" href="">窗口1</a> <a onclick="ShowHide('2',null);return false;"
href="">窗口2</a> <a onclick="ShowHide('3',null);return false;" href="">窗口3</a>
<p>
<div id="abc">
</div>
查找更多代码,请访问:<a href="http://www.lanrentuku.com" target="_blank">懒人图库</a></p></HTML>------------------------------------------------
不好意思啊。昨天临时有事
代码如上,我稍微做了一点改动,解决了captureEvents 在火狐里面过时的错误。。
但是你的样式不显示我解决不了,因为火狐里面不支持font-family:webdings 字体。
我建议你把 最小化最大化和关闭按钮做成图片,这样更美观,也不会出现这种问题了
我拿你的在ie里面没有拖动没有错误。。
在火狐里面拖动有错误。。
我现在的在ie火狐里面都没有错误啊。。
还要说下,我的是ie6
刚刚发的是之前改的
没有错误的在下面
-----------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <script type="text/javascript" language="JScript">
//可以打包为js文件;
var x_open_ie5 = document.all && document.getElementById;
var x_open_ns6 = document.getElementById && !document.all;
var x0 = 0, y0 = 0, x1 = 0, y1 = 0;
var offx = 6, offy = 6;
var moveable = false;
var hover = 'orange', normal = '#336699'; //color;
var index = 10000; //z-index;
//开始拖动;
function startDrag(obj, event)
{
drag(this,event);
stopDrag(this);
//定义对象;
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, e)
{
if (moveable)
{2010-1-14
var evt = x_open_ns6 ? e : event;
var win = obj.parentNode;
var sha = win.nextSibling;
win.style.left = x1 + evt.clientX - x0;
win.style.top = y1 + evt.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;
sha.style.left = obj.parentNode.style.left;
sha.style.top = obj.parentNode.style.top;
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 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:8pt;"
+ "font-family:Tahoma;"
+ "position:absolute;"
+ "cursor:default;"
+ "border:2px solid " + normal + ";"
+ "' "
+ "onmousedown='getFocus(this)'>"
+ "<div id=d1 "
+ "style='"
+ "background-color:" + normal + ";"
+ "width:" + (this.width - 2 * 2) + ";"
+ "height:20;"
+ "color:white;"
+ "' "
+ "onmousedown='startDrag(this,event)' "
+ "onmouseup='stopDrag(this)' "
+ "onmousemove='drag(this,event)' "
+ "ondblclick='min(this.childNodes[1])'"
+ ">"
+ "<span id=s1 style='width:" + (this.width - 2 * 12 - 4) + ";'>" + this.title + "</span>"
+ "<span id=s2 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='min(this)'></span>"
+ "<span id=s3 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='ShowHide(\"" + this.id + "\",null)'>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 id=xMsg" + this.id + "bg 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);"
+ "'></div>";
document.body.innerHTML += str;
var s1=document.getElementById("s1");
//s1.setAttribute("width",(this.width - 2 * 12 - 4));
s1.style.width=(this.width - 2 * 12 - 4);
//alert(s1.style.width)
s1.style.paddingLeft="3px"; var s2=document.getElementById("s2");
s2.style.fontFamily="webdings";
s2.innerHTML="0"
var s3=document.getElementById("s3");
s3.style.fontFamily="webdings";
s3.innerHTML="r"
}
//显示隐藏窗口
function ShowHide(id, dis)
{
var bdisplay = (dis == null) ? ((document.getElementById("xMsg" + id).style.display == "") ? "none" : "") : dis
document.getElementById("xMsg" + id).style.display = bdisplay;
document.getElementById("xMsg" + id + "bg").style.display = bdisplay;
}
//-->
</script><script language="javascript">
function initialize()
{
var a = new xWin("1", 160, 200, 200, 200, "窗口1", "xWin A Cool Pop Div WindowXueMu.Net2006-5-13");
var b = new xWin("2", 240, 200, 100, 100, "窗口2", "Welcome to visited my personal website:<a href=http://www.xuemu.net target=_blank>http://www.xuemu.net</a>请多提建议噢感谢您的关注!");
var c = new xWin("3", 200, 160, 250, 50, "窗口3", "Copyright by <a href='#'>Wildwind</a>!");
ShowHide("1", "none"); //隐藏窗口1
}
window.onload = initialize;
</script><base target="_blank">
<a onclick="ShowHide('1',null);return false;" href="">窗口1</a> <a onclick="ShowHide('2',null);return false;"
href="">窗口2</a> <a onclick="ShowHide('3',null);return false;" href="">窗口3</a>
<p>
<div id="abc">
</div>
查找更多代码,请访问:<a href="http://www.lanrentuku.com" target="_blank">懒人图库</a></p></HTML>
-----------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <script type="text/javascript" language="JScript">
//可以打包为js文件;
var x_open_ie5 = document.all && document.getElementById;
var x_open_ns6 = document.getElementById && !document.all;
var x0 = 0, y0 = 0, x1 = 0, y1 = 0;
var offx = 6, offy = 6;
var moveable = false;
var hover = 'orange', normal = '#336699'; //color;
var index = 10000; //z-index;
//开始拖动;
function startDrag(obj, event)
{
drag(this,event);
stopDrag(this);
//定义对象;
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, e)
{
if (moveable)
{2010-1-14
var evt = x_open_ns6 ? e : event;
var win = obj.parentNode;
var sha = win.nextSibling;
win.style.left = x1 + evt.clientX - x0;
win.style.top = y1 + evt.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;
sha.style.left = obj.parentNode.style.left;
sha.style.top = obj.parentNode.style.top;
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 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:8pt;"
+ "font-family:Tahoma;"
+ "position:absolute;"
+ "cursor:default;"
+ "border:2px solid " + normal + ";"
+ "' "
+ "onmousedown='getFocus(this)'>"
+ "<div id=d1 "
+ "style='"
+ "background-color:" + normal + ";"
+ "width:" + (this.width - 2 * 2) + ";"
+ "height:20;"
+ "color:white;"
+ "' "
+ "onmousedown='startDrag(this,event)' "
+ "onmouseup='stopDrag(this)' "
+ "onmousemove='drag(this,event)' "
+ "ondblclick='min(this.childNodes[1])'"
+ ">"
+ "<span id=s1 style='width:" + (this.width - 2 * 12 - 4) + ";'>" + this.title + "</span>"
+ "<span id=s2 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='min(this)'></span>"
+ "<span id=s3 style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='ShowHide(\"" + this.id + "\",null)'>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 id=xMsg" + this.id + "bg 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);"
+ "'></div>";
document.body.innerHTML += str;
var s1=document.getElementById("s1");
//s1.setAttribute("width",(this.width - 2 * 12 - 4));
s1.style.width=(this.width - 2 * 12 - 4);
//alert(s1.style.width)
s1.style.paddingLeft="3px"; var s2=document.getElementById("s2");
s2.style.fontFamily="webdings";
s2.innerHTML="0"
var s3=document.getElementById("s3");
s3.style.fontFamily="webdings";
s3.innerHTML="r"
}
//显示隐藏窗口
function ShowHide(id, dis)
{
var bdisplay = (dis == null) ? ((document.getElementById("xMsg" + id).style.display == "") ? "none" : "") : dis
document.getElementById("xMsg" + id).style.display = bdisplay;
document.getElementById("xMsg" + id + "bg").style.display = bdisplay;
}
//-->
</script><script language="javascript">
function initialize()
{
var a = new xWin("1", 160, 200, 200, 200, "窗口1", "xWin A Cool Pop Div WindowXueMu.Net2006-5-13");
var b = new xWin("2", 240, 200, 100, 100, "窗口2", "Welcome to visited my personal website:<a href=http://www.xuemu.net target=_blank>http://www.xuemu.net</a>请多提建议噢感谢您的关注!");
var c = new xWin("3", 200, 160, 250, 50, "窗口3", "Copyright by <a href='#'>Wildwind</a>!");
ShowHide("1", "none"); //隐藏窗口1
}
window.onload = initialize;
</script><base target="_blank">
<a onclick="ShowHide('1',null);return false;" href="">窗口1</a> <a onclick="ShowHide('2',null);return false;"
href="">窗口2</a> <a onclick="ShowHide('3',null);return false;" href="">窗口3</a>
<p>
<div id="abc">
</div>
查找更多代码,请访问:<a href="http://www.lanrentuku.com" target="_blank">懒人图库</a></p></HTML>