<!doctype html><html><head>?? ?<meta charset="UTF-8">?? ?<title>Document</title>?? ?<style type="text/css">?? ?#div1{width: 100px;height:100px;background:red;position: absolute;}?? ?</style>?? ?<script type="text/javascript">?? ?? window.onload=function()?? ?{?? ??? ?var oDiv=document.getElementById('div1');?? ??? ?var disX=0;//創(chuàng)建一個(gè)變量用來獲取鼠標(biāo)橫向坐標(biāo)???????????? ??? ?var disY=0????????????????????? ??????????????????????? ????????????? ??? ?if(oDiv.setCapture)??????????? ??? ? ?? ??? ?oDiv.onmousedown=function(ev)//當(dāng)鼠標(biāo)按下時(shí),獲取鼠標(biāo)位置?? ??? ?{???????????????????????????????? var oEvent=ev||event;????????????????????????????????? disX=oEvent.clientX-oDiv.offsetLeft;//鼠標(biāo)位置等于可視區(qū)鼠標(biāo)位置-需要移動(dòng)的物體的offsetLeft????????????????????????????????? disY=oEvent.clientY-oDiv.offsetTop;??????????????????????? ????????????????????????????????????? oDiv.onmousemove=function(ev){???????????????????????????????? ??? ???????????? var oEvent=ev||event;?????????????????????? ??? ??? ??? ?var l=oEvent.clientX-disX;?????????????????????? ??? ??? ??? ?var t=oEvent.clientY-disY;?????????????????????? ??? ??? ??? ?if(l<0){l=0}?????????????????????? ??? ??? ??? ??? ?else if(l>document.documentElement.clientWidth-oDiv.offsetWidth)?????????????????????? ??? ??? ??? ??? ?{l=document.documentElement.clientWidth-oDiv.offsetWidth}?????????????????????? ??????????????????????? ??? ??? ??? ?if(t<0){t=0}?????????????????????? ??? ??? ??? ??? ?else if(t>document.documentElement.clientHeight-oDiv.offsetHeight)?????????????????????? ??? ??? ??? ??? ?{t=document.documentElement.clientHeight-oDiv.offsetHeight}?????????????????????? ??????????????????????? ??? ??? ??? ?oDiv.style.left=l+'px';?????????????????????? ??? ??? ??? ?oDiv.style.top=t+'px'?????????????????????? ??? ??? ??? ?????????????????????????????????? }?????????????????????? ??????????????????????? ??? ??? ?oDiv.onmouseup=function()//當(dāng)鼠標(biāo)放開時(shí),讓函數(shù)取消?????????????????????? ??? ??? ?{?????????????????????? ??? ??? ??? ?this.onmousemove=null;?????????????????????? ??? ??? ??? ?this.onmouseup=null?????????????????????? ??? ??? ??? ?oDiv.releaseCapture()?????????????????????? ??? ??? ??? ??????????????????????? ??? ??? ?} ??????????????????????? ??? ??? ?oDiv.setCapture();???????????????????????????????????????????????????????????????????????????????????????? ??? ??? ?}?? ??? ?else?? ??? ?{?? ??? ?oDiv.onmousedown=function(ev)//當(dāng)鼠標(biāo)按下時(shí),獲取鼠標(biāo)位置?? ??? ?{???????????????????????????????? var oEvent=ev||event;????????????????????????????????? disX=oEvent.clientX-oDiv.offsetLeft;//鼠標(biāo)位置等于可視區(qū)鼠標(biāo)位置-需要移動(dòng)的物體的offsetLeft????????????????????????????????? disY=oEvent.clientY-oDiv.offsetTop;??????????????????????? ????????????????????????????????????? document.onmousemove=function(ev){???????????????????????????????? ??? ?var oEvent=ev||event;?????????????????????? ??? ??? ??? ?var l=oEvent.clientX-disX;?????????????????????? ??? ??? ??? ?var t=oEvent.clientY-disY;?????????????????????? ??? ??? ??? ?if(l<0){l=0}?????????????????????? ??? ??? ??? ??? ?else if(l>document.documentElement.clientWidth-oDiv.offsetWidth)?????????????????????? ??? ??? ??? ??? ?{l=document.documentElement.clientWidth-oDiv.offsetWidth}?????????????????????? ??????????????????????? ??? ??? ??? ?if(t<0){t=0}?????????????????????? ??? ??? ??? ??? ?else if(t>document.documentElement.clientHeight-oDiv.offsetHeight)?????????????????????? ??? ??? ??? ??? ?{t=document.documentElement.clientHeight-oDiv.offsetHeight}?????????????????????? ??????????????????????? ??? ??? ??? ?oDiv.style.left=l+'px';?????????????????????? ??? ??? ??? ?oDiv.style.top=t+'px'?????????????????????? ??? ??? ??? ?????????????????????????????????? }?????????????????????? ??????????????????????? ??? ??? ?document.onmouseup=function()//當(dāng)鼠標(biāo)放開時(shí),讓函數(shù)取消?????????????????????? ??? ??? ?{?????????????????????? ??? ??? ??? ?this.onmousemove=null;?????????????????????? ??? ??? ??? ?this.onmouseup=null?????????????????????? ??? ??? ??? ?oDiv.releaseCapture()?????????????????????? ??? ??? ??? ??????????????????????? ??? ??? ?}? return false???????????????????????????????????????????????????????????????????????????????????? ??? ??? ?}?? ?}?? ?</script></head><body><div id='div1'>nininiinnn</div>xnsuduwjndjkmmmmmmmmmmmmmm?xmisjdnusdjhhhhhhhhhhhhd<br>?? ?</body></html>
希望拖拽窗口中在ie下,能阻止選中問題的問題,為什么這里的setCapture不起效果
慕粉4084340
2016-10-16 17:44:15