zoukankan      html  css  js  c++  java
  • 表格数据上下行互换位置

    <!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>
        <title>表格数据上下行互换位置</title>
        <script src="js/jquery-1.7.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                //上移
                $("input.upbtn").each(function () {
                    $(this).click(function () {
                        var $tr = $(this).parents("tr");
                        if ($tr.index() != 0) {
                            $tr.prev().before($tr);
                        }
                    });
                });
                //下移
                var trLength = $("input.downbtn").length;           
                $("input.downbtn").each(function () {
                    $(this).click(function () {
                        var $tr = $(this).parents("tr");                  
                        if ($tr.index() != trLength - 1) {                      
                            $tr.next().after($tr);
                        }
                    });
                });
            });
        
        </script>
    </head>
    <body>
    <table border="1" cellpadding=0 cellspacing=0>
        <tr>
            <td>6</td>
            <td>xxxx66xxx</td>
            <td>2013-5-26</td>
            <td><input type="button" value="上移" class="upbtn" /><input type="button" value="下移" class="downbtn" /></td>
        </tr>
        <tr>
            <td>7</td>
            <td>xxxx77xxx</td>
            <td>2013-5-27</td>
            <td><input type="button" value="上移" class="upbtn" /><input type="button" value="下移" class="downbtn" /></td>
        </tr>
        <tr>
            <td>8</td>
            <td>xxx88xxxx</td>
            <td>2013-5-28</td>
            <td><input type="button" value="上移" class="upbtn" /><input type="button" value="下移" class="downbtn" /></td>
        </tr>
    </table>
    </body>
    </html>


  • 相关阅读:
    详解Bootstrap进度条组件
    详解Bootstrap缩略图组件及警示框组件
    详解Bootstrap表单组件
    spring注解-@Autowired。@Resource。@Service
    spring注解-@Transactional事务几点注意
    17_8_9 Spring 注入
    MySQL常用语句
    Mysql 远程登录及常用命令
    数据库(外键及其约束理解)
    C语言队列(数组内核)
  • 原文地址:https://www.cnblogs.com/moqiang02/p/4061103.html
Copyright © 2011-2022 走看看