点击这里给我发消息 点击这里给我发消息
首页 > 行业资讯 > HTML>详细内容

HTML拖放表格

添加时间:2011-7-17
    相关阅读: HTML
<style>
*{font-size:12px}
.dragTable{
font-size:12px;
margin-bottom:5px;
}
td{vertical-align:top;}
.dragTR{
cursor:move;
color:#7787cc;
background-color:#e5eef9;
height:20px;
padding-left:5px;
font-weight:bold;
}
#parentTable{
border-collapse:collapse;
letter-spacing:25px;
}
</style>
<scriptdefer>
varDrag={dragged:false,
ao:null,
tdiv:null,
dragStart:function(){
Drag.ao=yle="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">event.srcElement;
if((Drag.ao.tagName=="TD")||(Drag.ao.tagName=="TR")){
Drag.ao=Drag.ao.offsetParent;
Drag.ao.style.zIndex=100;
}else
return;
Drag.dragged=true;
Drag.tdiv=document.createElement("div");
Drag.tdiv.innerHTML=Drag.ao.outerHTML;
Drag.ao.style.border="1pxdashedred";
Drag.tdiv.style.display="block";
Drag.tdiv.style.position="absolute";
Drag.tdiv.style.filter="alpha(opacity=70)";
Drag.tdiv.style.cursor="move";
Drag.tdiv.style.border="1pxsolid#000000";
Drag.tdiv.style.width=Drag.ao.offsetWidth;
Drag.tdiv.style.height=Drag.ao.offsetHeight;
Drag.tdiv.style.top=Drag.getInfo(Drag.ao).top;
Drag.tdiv.style.left=Drag.getInfo(Drag.ao).left;
document.body.appendChild(Drag.tdiv);
Drag.lastX=event.clientX;
Drag.lastY=event.clientY;
Drag.lastLeft=Drag.tdiv.style.left;
Drag.lastTop
LOR: #000000; BACKGROUND-COLOR: #f5f5f5">=Drag.tdiv.style.top;
},
draging:function(){//重要:判断MOUSE的位置
if(!Drag.dragged||Drag.ao==null)return;
vartX=event.clientX;
vartY=event.clientY;
Drag.tdiv.style.left=parseInt(Drag.lastLeft)+tX-Drag.lastX;
Drag.tdiv.style.top=parseInt(Drag.lastTop)+tY-Drag.lastY;
for(vari=0;i<parentTable.cells.length;i++){
varparentCell=Drag.getInfo(parentTable.cells[i]);
if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
 varsubTables=parentTable.cells[i].getElementsByTagName("table");
 if(subTables.length==0){
if
n style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
  parentTable.cells[i].appendChild(Drag.ao);
  }
  break;
 }
 for(varj=0;j<subTables.length;j++){
  varsubTable=Drag.getInfo(subTables[j]);
  if(tX>=subTable.left&&tX<=subTable.right&&tY>=subTable.top&&tY<=subTable.bottom){
  parentTable.cells[i].insertBefore(Drag.ao,subTables[j]);
  break;
  }else{
  parentTable.cells[i].appendChild(Drag.ao);
  }
 }
}
}
}
dragEnd:function(){
if(!Drag.dragged)return;
Drag.dragged=false;
Drag.mm=Drag.repos(150,15);
Drag.ao.style.borderWidth="0px";
Drag.ao.style.borderTop="0; BACKGROUND-COLOR: #f5f5f5">1pxsolid#3366cc";
Drag.tdiv.style.borderWidth="0px";
Drag.ao.style.zIndex=1;
}
getInfo:function(o){//取得坐标
varto=newObject();
to.left=to.right=to.top=to.bottom=0;
vartwidth=o.offsetWidth;
vartheight=o.offsetHeight;
while(o!=document.body){
to.left+=o.offsetLeft;
to.top+=o.offsetTop;
o=o.offsetParent;
}
to.right=to.left+twidth;
to.bottom=to.top+theight;
returnto;
}
repos:function(aa,ab){
varf=Drag.tdiv.filters.alpha.opacity;
vartl=parseInt(Drag.getInfo(Drag.tdiv).left);
vartt=parseInt(Drag.getInfo(Drag.tdiv).top);
varkl=(tl-Drag.getInfo(Drag.ao).left)/ab;
varkt=;
BACKGROUND-COLOR: #f5f5f5">(tt-Drag.getInfo(Drag.ao).top)/ab;
varkf=f/ab;
returnsetInterval(function(){if(ab<1){
   clearInterval(Drag.mm);
   Drag.tdiv.removeNode(true);
   Drag.ao=null;
   return;
   }
  ab--;
  tl-=kl;
  tt-=kt;
  f-=kf;
  Drag.tdiv.style.left=parseInt(tl)+"px";
  Drag.tdiv.style.top=parseInt(tt)+"px";
  Drag.tdiv.filters.alpha.opacity=f;
  }
,aa/ab)
}
inint:function(){//初始化
for(vari=0;i<parentTable.cells.length;i++){
varsubTables=parentTable.cells[i].getElementsByTagName("table");
for(varj=0;j<subTables.length;j++){
 if(subTables[j].className!="dragTable")break;
 subTables[j].rows[0].className="dragTR";
 subTables[j].rows[0].attachEvent("onmousedown",Drag.dragStart);
}
}
document.onmousemove=Drag.draging;
document.onmouseup=Drag.dragEnd;
}
//endofObjectDrag
}
Drag.inint();
function_show(str){
varw=window.open('''','''');
vard=w.document;
d.open();
str=str.replace(/=(?!")(.*?)(?!")(|>)/g,"="{GetProperty(Content)}"$2");
str=str.replace(/(<)(.*?)(>)/g,"
OR: #f5f5f5"><spanstyle=''color:red;''><$2></span><br/>");
str=str.replace(/ /g,"<br/> ");
d.write(str);
}
</script>
<tablewidth="30%"height=200border="0"cellpadding="0"cellspacing="0"id="parentTable">
 <tr>
  <tdvalgin="top">
    <tablewidth="100%"border=0cellspacing="0"class="dragTable">
     <tr>
      <td>表格1</td>
     </tr>
    </table>
    <tablewidth="100%"border=0cellspacing="0"class="dragTable">
     <tr>
      <td>表格2</td>
     </tr>
    </table>
 <tablewidth="100%"border=0
LOR: #ff0000">cellspacing="0"class="dragTable">
  <tr>
  <td>表格3</td>
  </tr>
  <tr>
  <td>
  <tablestyle="width:100%">
  <tr>
  <td>a</td>
  <td>b</td>
  <td>c</td>
  </tr>
  <tr>
  <td>d</td>
  <td>e</td>
  <td>f</td>
  </tr>
  </table>
  </td>
  </tr>
  </table></td>
  </tr>
  </table> 本文作者:未知
咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册