使用JQuery 对表格数据上下移动

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script type="text/javascript">

 $(document).ready(function() {
   
    //上移处理
     $("#btn_up").click(function(){
         var htm ='';
         $("input[name=check_box_show]").each(function(){
                if($(this).attr('checked')){
                    htm += $(this).val();

                    //alert($(this).parents("tr").clone(true));判断是否第一条,第一条不移动

                    if($(this).val()==$("#tab_show_info :first-child :checkbox").val()){
                        alert("'"+$(this).parents("td").text() +"' is the First !");
                        return ;
                    }
                    //向上移动
                    $(this).parents("tr").prev("tr").before(
                            $(this).parents("tr").clone(true));
                    $(this).parents("tr").remove();//删除当前的
                }
          });
         if(htm ==''){
                alert('Please Select "Show Information"!');
        }
    });

     $("#btn_down").click(function(){
         var htm ='';
         //alert();
         $("input[name=check_box_show]").each(function(){
                if($(this).attr('checked')){
                    htm += $(this).val();
                    //alert($(this).parents("tr").clone(true));判断是中最后一条
                    if($(this).val()==$("#tab_show_info :last-child :checkbox").val()){
                        alert("'"+$(this).parents("td").text() +"' is the Last !");
                        return ;
                    }
                    //复制并向下移动
                    $(this).parents("tr").next("tr").append(
                            $(this).parents("tr").clone(true));
                    $(this).parents("tr").remove();//删除当前的
                }
          });
         if(htm ==''){
            alert('Please Select "Show Information"!');
        }
    });
        
   
});

</script>

</head>
<body class="elite">

<div style="float:left;width:470px;">

      <table class="ctrtable" width="100%" align="right" id="tab_show_info">
                 <c:forEach items="${showPropertys}" var="property">
                <tr>
                    <td>
                        <input type="checkbox" name="check_box_show" value="avaProperty1" />
                         ap1
                    </td>
                </tr>

              <tr>
                    <td>
                        <input type="checkbox" name="check_box_show" value="avaProperty3" />
                         ap2
                    </td>
                </tr>

              <tr>
                    <td>
                        <input type="checkbox" name="check_box_show" value="avaProperty3" />
                         ap3
                    </td>
                </tr>
                </c:forEach>
            </table>

</div>

<div style="float:left;width:50px;padding-top:100px;">
   <span style="padding-top: 10px;padding-botton:10px;margin-top:10px;margin-botton:10px;">
            <a class="button-b" id="btn_up"><span>&nbsp;&nbsp;Up&nbsp;&nbsp;</span> </a>
       </span>
       <br/>
           <br/>
               <br/>
       <span style="padding-top: 10px;padding-botton:10px;margin-top:10px;margin-botton:10px;">
    <a class="button-b" id="btn_down"><span>Down</span> </a>
     </span>
     <br/>
           <br/>
   </div>

</body>

</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值