请你们看一下这个例子
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<SCRIPT language="jscript">
var ms=0;
function did(obj){
    ms=obj;
    event.srcElement.setCapture();
    x=document.all(ms).style.pixelLeft-event.x;
    y=document.all(ms).style.pixelTop-event.y;
}function document.onmousemove(){
if(ms){
    document.all(ms).style.pixelLeft=x+event.x;
    document.all(ms).style.pixelTop=y+event.y;
    document.all("pos").innerText=event.x;
//curr=event.srcElement.parentElement.rowIndex;
//document.all("a1")rows[curr].style.background="#ff0000";
//vent.srcElement.parentElement.className="BottomLine";
    }
}function document.onmouseup(){
if(ms){
    event.srcElement.releaseCapture();
    ms=0;
    }
}
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="css.css" rel="stylesheet" type="text/css">
</head><body>
<table id="a1" width="75%" border="1">
  <tr> 
    <td width="6%">&nbsp;<div id="Layer1" style="position:absolute; width:11px; height:4px; z-index:1"><img src="tt.gif"  onmousedown="did('Layer1')" ></div></td>
    <td width="94%"><table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td class="NoLine">把图片拖放在这儿</td>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
    <td width="94%" id="pos" >&nbsp;</td>
  </tr>
</table>
</body>
</html>

解决方案 »

  1.   

    <body>
    <img id=s src="csdn.gif" onmousedown="did(this)">
    <script>  
    var ms;
    function did(obj){
    ms=obj;
    event.srcElement.setCapture();
    }function document.onmouseup(){
    if(ms&&document.elementFromPoint(event.x,event.y).tagName=="TD"){
    event.srcElement.releaseCapture();
      document.elementFromPoint(event.x,event.y).appendChild(ms)
      }
    ms=null;
    }
    </script>
    <table border="1" width="100">
      <tr>
        <td width="50%"> </td>
        <td width="50%"> </td>
      </tr>
      <tr>
        <td width="50%"> </td>
        <td width="50%"> </td>
      </tr>
    </table>
      

  2.   


    <div id=MoveDiv style=position:absolute;left:0;top:0;width:200;height:200;background:red ></div>
    <SCRIPT  LANGUAGE=vbs >
    dim px,py
    dim IsIn
    IsIn=false
    Sub MoveDiv_onmousedown px=window.event.x- MoveDiv.style.pixelleft
    py=window.event.y- MoveDiv.style.pixeltop
    IsIn=true
    End SubSub MoveDiv_onmousemove
    if IsIn=true then 
    MoveDiv.style.left=window.event.x-px
    MoveDiv.style.top=window.event.y-py
    end if
    End Sub
    Sub MoveDiv_onmouseup
    IsIn=false
    End Sub
    </SCRIPT>