<html> <script type="text/javascript"> var D = new Function('obj', 'return document.getElementById(obj) ') function Move_obj(e){ o = window.event; D(e).onmousedown = function(){ D(e).setCapture(true);
this.style.position = "absolute"; x = o.clientX; y = o.clientY; xd = D(e).offsetLeft; yd = D(e).offsetTop;
<script type="text/javascript"> var D = new Function('obj', 'return document.getElementById(obj) ') function Move_obj(e){ o = window.event; D(e).onmousedown = function(){ D(e).setCapture(true);
this.style.position = "absolute"; x = o.clientX; y = o.clientY; xd = D(e).offsetLeft; yd = D(e).offsetTop;
<script type="text/javascript">
var D = new Function('obj', 'return document.getElementById(obj) ')
function Move_obj(e){
o = window.event;
D(e).onmousedown = function(){
D(e).setCapture(true);
this.style.position = "absolute";
x = o.clientX;
y = o.clientY;
xd = D(e).offsetLeft;
yd = D(e).offsetTop;
D(e).onmousemove = function(){
D(e).style.left = o.clientX - x + xd + "px";
D(e).style.top = o.clientY - y + yd + "px";
}
D(e).onmouseup = function(){
D(e).onmousemove = null;
D(e).onmouseup = null;
D(e).releasecapture();
}
}
}
</script>
</head>
<body>
<div id="test" style="background-color: #0099CC; width: 200px; height: 100px; border: 1px #000 solid;" onmouseover='Move_obj("test")'>
鼠标过来点击拖动层
</div>
</body>
</html>
var D = new Function('obj', 'return document.getElementById(obj) ')
function Move_obj(e){
o = window.event;
D(e).onmousedown = function(){
D(e).setCapture(true);
this.style.position = "absolute";
x = o.clientX;
y = o.clientY;
xd = D(e).offsetLeft;
yd = D(e).offsetTop;
D(e).onmousemove = function(){
D(e).style.left = o.clientX - x + xd + "px";
D(e).style.top = o.clientY - y + yd + "px";
}
D(e).onmouseup = function(){
D(e).onmousemove = null;
D(e).releaseCapture()
}
}
}
</script>
根据你写的修改了一下,居然没有测试就发上来了。呵呵。不过还是要谢谢你。给我了一个很好的思路!!