移动表格

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
html, body{
    font-size:12px;
}
table{
    border-collapse:collapse;
}
</style>
<script type="text/javascript">
function $(id){
    return document.getElementById(id);
}
function getTable(row){
    while(row && row.tagName.toLowerCase() != "table"){
        row = row.parentNode;
    }
    return row;
}
function clickRow(row){
    if(row.style.backgroundColor == ""){
        row.style.backgroundColor = "#EEE";
    }else{
        row.style.backgroundColor = "";
    }
}
function dblclickRow(row){
    row.style.backgroundColor = "";
    moveRow(row);
}
function moveRow(row){
    var ts = getTable(row);
    var td = null;
    if(ts.id == "tbSource"){
        td = $("tbDest");
    }else{
        td = $("tbSource");
    }
    td.getElementsByTagName("tbody")[0].appendChild(row);
}
function moveTable(id){
    var tb = $(id);
    var len = tb.rows.length;
    for(var i=len-1; i>=0; i--){
        if(tb.rows[i].style.backgroundColor != ""){
            tb.rows[i].style.backgroundColor = "";
            moveRow(tb.rows[i]);
        }
    }
}
window.onload = function(){
    var tbSource = $("tbSource");
    for(var i=0; i<tbSource.rows.length; i++){
        tbSource.rows[i].onclick = function(){
            clickRow(this);
        };
        tbSource.rows[i].ondblclick = function(){
            dblclickRow(this);
        };
    }
};
</script>
</head>

<body>
<table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" valign="top"><table width="260" border="1" cellspacing="0" cellpadding="6" id="tbSource">
      <tr>
        <td bgcolor="#CCCCCC"><strong>ID</strong></td>
        <td bgcolor="#CCCCCC"><strong>姓名</strong></td>
        <td bgcolor="#CCCCCC"><strong>货物</strong></td>
        <td bgcolor="#CCCCCC"><strong>件数</strong></td>
      </tr>
      <tr>
        <td>1</td>
        <td>A</td>
        <td>D</td>
        <td>5</td>
      </tr>
      <tr>
        <td>2</td>
        <td>B</td>
        <td>E</td>
        <td>87</td>
      </tr>
      <tr>
        <td>3</td>
        <td>C</td>
        <td>F</td>
        <td>4</td>
      </tr>
    </table></td>
    <td align="center"><input type="button" name="btn1" id="btn1" value=" &gt;&gt; " οnclick="moveTable('tbSource');" /><br /><br />
    <input type="button" name="btn2" id="btn2" value=" &lt;&lt; " οnclick="moveTable('tbDest');" /></td>
    <td align="center" valign="top">
    <table width="260" border="1" cellspacing="0" cellpadding="6" id="tbDest">
      <tr>
        <td bgcolor="#CCCCCC"><strong>ID</strong></td>
        <td bgcolor="#CCCCCC"><strong>姓名</strong></td>
        <td bgcolor="#CCCCCC"><strong>货物</strong></td>
        <td bgcolor="#CCCCCC"><strong>件数</strong></td>
      </tr>
    </table></td>
  </tr>
</table>

</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值