<div class="codetitle"> <span><a style="CURSOR: pointer" data="28155" class="copybut" id="copybut28155" onclick="doCopy('code28155')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code28155"> <br> <br><title>测试可动div</title> <br><script language="javascript" type="text/javascript"> <BR>var offset_x; <BR>var offset_y; <BR>function Milan_StartMove(oEvent) <BR>{ <BR>var whichButton; <BR>if(document.all&&oEvent.button==1) whichButton=true; <BR>else { if(oEvent.button==0)whichButton=true;} <BR>if(whichButton) <BR>{ <BR>var oDiv=document.getElementById("oDiv"); <BR>offset_x=parseInt(oEvent.clientX-oDiv.offsetLeft); <BR>offset_y=parseInt(oEvent.clientY-oDiv.offsetTop); <BR>document.documentElement.onmousemove=function(mEvent) <BR>{ <BR>var eEvent; <BR>if(document.all) eEvent=event; <BR>else{eEvent=mEvent;} <BR>var oDiv=document.getElementById("oDiv"); <BR>var x=eEvent.clientX-offset_x; <BR>var y=eEvent.clientY-offset_y; <BR>oDiv.style.left=(x)+"px"; <BR>oDiv.style.top=(y)+"px"; <BR>} <BR>} <BR>} <BR>function Milan_StopMove(oEvent){document.documentElement.onmousemove=null; } <BR></script> <br> <br> <br><div id="oDiv" onmousedown="Milan_StartMove(event)" onmouseup="Milan_StopMove(event)"> <br>style="cursor:move;position:absolute;width:100px;height:60px;border:1px solid <br><br>silver;left:100px;top:100px;z-index:9999;"></div> <br> <br> </div> <br>document.all[]是文档中所有标签组成的一个数组变量,包括了文档对象中所有元素; <br>event.button的值:0没按键 1按左键 2按右键 3按左和右键 4按中间键 5按左和中间键 6按右和中间键 7按所有的键 <br><br>下面对此代码进行改进,模仿window,并且让它可以盖住select <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="19869" class="copybut" id="copybut19869" onclick="doCopy('code19869')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code19869"> <br> <br> <br> <br><title>测试可动div</title> <br><script language="javascript" type="text/javascript"> <BR>var offset_x; <BR>var offset_y; <BR>function Milan_StartMove(oEvent,div_id) <BR>{ <BR>var whichButton; <BR>if(document.all&&oEvent.button==1) whichButton=true; <BR>else { if(oEvent.button==0)whichButton=true;} <BR>if(whichButton) <BR>{ <BR>var oDiv=div_id; <BR>offset_x=parseInt(oEvent.clientX-oDiv.offsetLeft); <BR>offset_y=parseInt(oEvent.clientY-oDiv.offsetTop); <BR>document.documentElement.onmousemove=function(mEvent) <BR>{ <BR>var eEvent; <BR>if(document.all) eEvent=event; <BR>else{eEvent=mEvent;} <BR>var oDiv=div_id; <BR>var x=eEvent.clientX-offset_x; <BR>var y=eEvent.clientY-offset_y; <BR>oDiv.style.left=(x)+"px"; <BR>oDiv.style.top=(y)+"px"; <BR>var d_oDiv=document.getElementById("disable_"+oDiv.id); <BR>d_oDiv.style.left=(x)+"px"; <BR>d_oDiv.style.top=(y)+"px"; <BR>} <BR>} <BR>} <BR>function Milan_StopMove(oEvent){document.documentElement.onmousemove=null; } <BR>function div_Close(o) <BR>{var oDiv=o; oDiv.style.display="none";var d_oDiv=document.getElementById("disable_"+o.id);d_oDiv.style.display="none";} <BR></script> <br> <br> <br><div id="oDiv" style="position:absolute;width:100px;height:60px;border:1px solid silver;left:100px;top:100px;z-index:9999;"> <br><div id="move" onmousedown="Milan_StartMove(event,this.parentNode)" onmouseup="Milan_StopMove(event)">style="cursor:move;width:100%;height:15px;background-color:#0066cc; font-size:10px;"> <br><div onclick="div_Close(this.parentNode.parentNode)" style="float:right; width:10px; height:100%; cursor:hand; background-color:#cc3333; color:White;font-size:15px;">X</div> <br> </div> <br><span>测试一下</span> <br> </div> <br><div id="disable_oDiv" style="position:absolute;left:100px;top:100px;width:100px; height:60px; z-index:9998;FILTER:alpha(opacity=50);"> <br><iframe src="about:blank" name="hiddenIframe" width="100%" frameborder="0" height="60px" title="遮盖层"></iframe> </div> <br><select name="ListHead1$DropDownList3" id="ListHead1_DropDownList3"> <br><option selected value=""></option> <br><option value="2">3333</option> <br><option value="6">1111</option> <br><option value="B">222</option> <br></select> <br> <br> <br> </div> <br>现在这个可拖动的div是不是好很多了?不用担心select了。之前放出来的只能在IE下正常工作,主要是用了parentElement,现在我把它换成parentNode,调整了CSS样式,这样在FF下也能正常运行了。 <br>