注意使用preventDefault防止浏览器的默认事件操作发生 复制代码 代码如下: <BR>var isDrag = false; <BR>function isIE(){ <BR>if(navigator.userAgent.indexOf("MSIE")>0){return true;} <BR>else{return false;} <BR>} <BR>function addListener(element,e,fn){ <BR>if(isIE()){element.attachEvent("on" + e,fn);} <BR>else{element.addEventListener(e,fn,false);} <BR>} <BR>function drag(e){ <BR>var e = e || window.event; <BR>var element = e.srcElement || e.target; <BR>if(e.preventDefault)e.preventDefault(); <BR>else e.returnvalue=false; <BR>isDrag = true; <BR>var relLeft = e.clientX - parseInt(element.style.left); <BR>var relTop = e.clientY - parseInt(element.style.top); <BR>element.onmouseup = function(){ isDrag = false; } <BR>document.onmousemove = function(e_move){ <BR>var e_move = e_move || window.event; <BR>if(isDrag){ <BR>element.style.left=e_move.clientX - relLeft + "px"; <BR>element.style.top=e_move.clientY - relTop + "px"; <BR>return false; <BR>} <BR>} <BR>} <BR>window.onload = function() <BR>{ <BR>var element = document.getElementById("elimg"); <BR>var element2 = document.getElementById("eldiv"); <BR>addListener(element,"mousedown",drag); <BR>addListener(element2,"mousedown",drag); <BR>} <BR>