<p><!DOCTYPEHTML></p><p><html><head><metacharset="utf-8"><title>无标题文档</title><style>#div1{width:100px;height:100px;background:red;position:absolute;}#div2{width:700px;height:500px;background:#CCC;position:relative;}</style><script>window.onl劳务派遣系统软件d=function(){varoDiv=document.getElementById('div1');varoDiv2=document.getElementById('div2');vardisX=0;vardisY=0;oDiv.onmousedown=function(ev){varoEvent=ev||event;disX=oEvent.clientX-oDiv.offsetLeft;disY=oEvent.clientY-oDiv.offsetTop;document.onmousemove=function(ev){varoEvent=ev||event;varl=oEvent.clientX-disX;vart=oEvent.clientY-disY;if(l<50){l=0;}elseif(l>oDiv2.offsetWidth-oDiv.offsetWidth){l=oDiv2.offsetWidth-oDiv.offsetWidth;}if(t<50){t=0;}elseif(t>oDiv2.offsetHeight-oDiv.offsetHeight){t=oDiv2.offsetHeight-oDiv.offsetHeight;}oDiv.style.left=l+'px';oDiv.style.top=t+'px';};document.onmouseup=function(){document.onmousemove=null;document.onmouseup=null;};returnfalse;};};</script></head><body><divid="div2"><divid="div1"></div></div></body></html>三个事件:down、move、up</p><p>限制范围——范围的大小计算比例——当前值/最大值</p>