表格拖拽实例

来源:互联网 发布:windows arp 清除 编辑:程序博客网 时间:2024/04/29 11:29

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Welcome to Northsnow Home</title>
<style>
.removableObj
{
height:25;position:relative;
}
</style>
<script language="javascript">
var beginMoving=false;
var sourceObj=null;
var objectObj=null;
var objectObj2=null;
function MouseDownToMove(obj){
obj.style.zIndex=1;
obj.mouseDownY=event.clientY;
obj.mouseDownX=event.clientX;
beginMoving=true;
obj.setCapture();
sourceObj=obj;
objectObj=null;
}

function MouseMoveToMove(obj){
    if(!beginMoving) return false;
obj.style.top = (event.clientY-obj.mouseDownY);
obj.style.left = (event.clientX-obj.mouseDownX);
}
function MouseUpToMove(obj){
if(!beginMoving) return false;
obj.releaseCapture();
obj.style.top=0;
obj.style.left=0;
obj.style.zIndex=0;
beginMoving=false;
window.setTimeout("swapFun()",20);
}

function MouseOverFun(obj)
{
 if(obj==sourceObj) return false;
 objectObj=obj;
}

function MouseOverFun2(obj)
{
 objectObj2=obj;
}

function swapFun()
{
if(sourceObj!=null && objectObj!=null) objectObj.insertAdjacentElement("beforeBegin",sourceObj);
else if(sourceObj!=null && objectObj2!=null) objectObj2.insertAdjacentElement("beforeEnd",sourceObj);
sourceObj=null;
objectObj=null;
objectObj2=null;
}
</script>
</head>

<body>

<table border="1" width="100%" height="58">
  <tr>
    <td width="34%" valign="top" height="46" onmouseover="MouseOverFun2(this);" >
      <table border="1" width="100%" bgcolor="#99CCFF" class="removableObj" onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);' onmouseover="MouseOverFun(this);" >
         <tr>
          <td width="23%">northsnow</td>
          <td width="21%">塞北的雪</td>
        </tr>
        <tr>
          <td width="23%">白骨精</td>
          <td width="21%">白龙马</td>
        </tr>
      </table><table border="1" width="100%" bgcolor="#FFCCFF" class="removableObj" onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);' onmouseover="MouseOverFun(this);" >
        <tr>
          <td width="21%">太上老君</td>
          <td width="35%">元始天尊</td>
        </tr>
        <tr>
          <td width="21%">太乙真人</td>
          <td width="35%">如来佛祖</td>
        </tr>
      </table>
  <table border="1" width="100%" bgcolor="#00CC99" class="removableObj" onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);' onmouseover="MouseOverFun(this);" >
         <tr>
          <td width="21%">镇元大仙</td>
          <td width="9%">卯日星君</td>
          <td width="35%">观音菩萨</td>
        </tr>
        <tr>
          <td width="21%">南极仙翁</td>
          <td width="9%">太白金星</td>
          <td width="35%">齐天大圣</td>
        </tr>
      </table>
     
    </td>
    <td width="32%" valign="top" height="52" onmouseover="MouseOverFun2(this);" >
  <table border="1" width="100%" bgcolor="#FF0000" class="removableObj" onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);' onmouseover="MouseOverFun(this);" >
        <tr>
          <td width="21%">灵宝道君</td>
        </tr>
        <tr>
          <td width="21%">通天教主</td>
        </tr>
      </table>   
      <table border="1" width="100%" bgcolor="#00FFFF" class="removableObj" onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);' onmouseover="MouseOverFun(this);" >
       <tr>
          <td width="21%">菩提老祖</td>
          <td width="35%">护身符哈</td>
          <td width="21%">接引道人</td>
          <td width="23%">准提道人</td>
        </tr>
        <tr>
          <td width="21%">嫦娥</td>
          <td width="35%">赤脚大仙</td>
          <td width="21%">太白金星</td>
          <td width="23%">四大天王</td>
        </tr>
      </table>

</td>
    <td width="34%" valign="top" height="52" onmouseover="MouseOverFun2(this);" >
  <table border="1" width="100%" bgcolor="#FF9966" class="removableObj" onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);' onmouseover="MouseOverFun(this);" >
        <tr>
          <td width="21%">卷廉大将</td>
          <td width="35%">猪八戒</td>
          <td width="21%">沙僧</td>
          <td width="23%">唐僧</td>
        </tr>
        <tr>
          <td width="21%">牛魔王</td>
          <td width="35%">铁扇公主</td>
          <td width="21%">哪吒</td>
          <td width="23%">杨戬</td>
        </tr>
      </table>   
      <table width="100%" border="1" bgcolor="#FFFFCC" class="removableObj" onmousedown='MouseDownToMove(this)' onmousemove='MouseMoveToMove(this)' onmouseup='MouseUpToMove(this);' onmouseover="MouseOverFun(this);" >
       <tr>
          <td width="87">李天王</td>
          <td width="115">千里眼</td>
        </tr>
        <tr>
          <td width="87">顺风耳</td>
          <td width="115">普贤菩萨</td>
        </tr>
        <tr>
          <td width="87">文殊菩萨</td>
          <td width="115">灵吉菩萨</td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>