这个对你有用:
http://community.csdn.net/Expert/topic/3810/3810715.xml?temp=.7833216

解决方案 »

  1.   

    rect可以放在一个div内,拖动div的时候,rect会跟着移动<html xmlns:v>
    <style>
    v\:*
    {
    behavior:url(#default#VML);
    position:relative;left:10px;top:10px;width:200px;height:200px;
    }
    div
    {
    background-color:green;position:absolute;left:10px;top:50px;
    width:230px;height:230px;
    border-width:2px;border-color:red;border-style:solid;
    t:expression(this.ondragstart=function(){startDrag(this)});
    e:expression(this.ondragend=function(){endDrag(this)});
    }
    </style>
    <script>
    var start_x=0;
    var start_y=0;
    var end_x=0;
    var end_y=0;
    function startDrag(obj)
    {
      start_x=obj.style.left;
      start_y=obj.style.top;
    }function endDrag(obj)
    {
      end_x=event.x;
      end_y=event.y;
      obj.style.left+=(end_x-start_x);
      obj.style.top+=(end_y-start_y);
      
    }
    </script>
    <body>
    <div>
    <v:rect fillcolor="red"/>
    </div>
    </body>
    </html>
      

  2.   

    先拖动div的绿色边缘一次,这时整个div处于选中状态,然后拖动rect
      

  3.   

    不好意思,改了一下:<html xmlns:v>
    <style>
    v\:*
    {
    behavior:url(#default#VML);
    position:relative;left:10px;top:10px;width:200px;height:200px;
    }
    div
    {
    background-color:green;position:absolute;left:10px;top:50px;
    width:230px;height:230px;
    border-width:2px;border-color:red;border-style:solid;
    t:expression(this.ondragstart=function(){startDrag(this)});
    e:expression(this.ondragend=function(){endDrag(this)});
    }
    </style>
    <script>
    var start_x=0;
    var start_y=0;
    var end_x=0;
    var end_y=0;
    function startDrag(obj)
    {
      start_x=obj.currentStyle.left;
      start_y=obj.currentStyle.top;
    }function endDrag(obj)
    {
      end_x=event.clientX;
      end_y=event.clientY;
      obj.style.left=(parseInt(obj.currentStyle.left)+end_x-parseInt(start_x)).toString()+'px';
      obj.style.top=(parseInt(obj.currentStyle.top)+end_y-parseInt(start_y)).toString()+'px';
    }
    </script>
    <body>
    <div>
    <v:rect fillcolor="red"/>
    </div>
    </body>
    </html>
      

  4.   

    哦。。可以了:)我是把它放在div里<div><v:rect fillcolor="red"/></div>,但没给div样式,可是我不明白为什么要有样式?我那样为什么不能直接选中div而拖动它?
      

  5.   

    不必定义div样式,只是测试的时候单纯的只有rect不好拖动:)
    <html xmlns:v>
    <style>
    v\:*
    {
    behavior:url(#default#VML);
    position:relative;left:10px;top:10px;width:200px;height:200px;
    t:expression(this.ondragstart=function(){startDrag(this)});
    e:expression(this.ondragend=function(){endDrag(this)});
    }
    </style>
    <script>
    var start_x=0;
    var start_y=0;
    var end_x=0;
    var end_y=0;
    function startDrag(obj)
    {
      start_x=obj.currentStyle.left;
      start_y=obj.currentStyle.top;
    }function endDrag(obj)
    {
      end_x=event.clientX;
      end_y=event.clientY;
      obj.style.left=(parseInt(obj.currentStyle.left)+end_x-parseInt(start_x)).toString()+'px';
      obj.style.top=(parseInt(obj.currentStyle.top)+end_y-parseInt(start_y)).toString()+'px';
    }
    </script>
    <body>
    <div>
    <v:rect fillcolor="red"/>
    </div>
    </body>
    </html>
      

  6.   

    哦,明白了:)
    t:expression(this.ondragstart=function(){startDrag(this)});
    e:expression(this.ondragend=function(){endDrag(this)});
    这两句是什么意思?不太明白阿
      

  7.   

    vivianfdlpw(),你还在马?如果两个矩形间用直线相连,如何保证拖动时线动态跟随物体? 谢谢,分不够可以再加,vml实在陌生。
      

  8.   

    好的,谢谢你。[email protected]