JS拖动技术--- 关于setCapture (转自 剑胆琴心-.Net学习笔记) 复制代码 代码如下: <BR><!-- <BR>window.onload=function(){ <BR>objDiv = document.getElementById('drag'); <BR>drag(objDiv); <BR>}; <BR>function drag(dv){ <BR>dv.onmousedown=function(e){ <BR>var d=document; <BR>e = e || window.event; <BR>var x= e.layerX || e.offsetX; <BR>var y= e.layerY || e.offsetY; <BR>//设置捕获范围 <BR>if(dv.setCapture){ <BR>dv.setCapture(); <BR>}else if(window.captureEvents){ <BR>window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP); <BR>} <br><br>d.onmousemove=function(e){ <BR>e= e || window.event; <BR>if(!e.pageX)e.pageX=e.clientX; <BR>if(!e.pageY)e.pageY=e.clientY; <BR>var tx=e.pageX-x; <BR>var ty=e.pageY-y; <BR>dv.style.left=tx; <BR>dv.style.top=ty; <BR>}; <BR>d.onmouseup=function(){ <BR>//取消捕获范围 <BR>if(dv.releaseCapture){ <BR>dv.releaseCapture(); <BR>}else if(window.captureEvents){ <BR>window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); <BR>} <BR>//清除事件 <BR>d.onmousemove=null; <BR>d.onmouseup=null; <BR>}; <BR>}; <BR>} <BR>//--> <BR> drag me