不多说
http://topic.csdn.net/u/20081117/10/D44871AF-3480-4AE0-AA02-E3AB334562BC.html

解决方案 »

  1.   

    <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;

                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>
      

  2.   

    <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).releaseCapture()
                    }
                }
            }
    </script>
    根据你写的修改了一下,居然没有测试就发上来了。呵呵。不过还是要谢谢你。给我了一个很好的思路!!