Jquery-ui的sortable插件之自由拖动排序-table

复制粘贴放入jsp文件即可使用

我注释部分是打算用本地的js和layui的样式,方便大家尝试,直接复制粘贴即可使用,样式自行引入吧

参考:https://blog.youkuaiyun.com/weixin_42322501/article/details/80514405

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>拖动排序-表格版</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">

    <script src="http://cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script>
    <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <%--<link rel="stylesheet" href="<%=request.getContextPath() %>/plugin/layui-v2.4.3/layui/css/layui.css" media="all">--%>
    <%--<script src="<%=request.getContextPath() %>/plugin/layui/layui/layui.js" charset="utf-8"></script>--%>
    <%--<script src="<%=request.getContextPath() %>/plugin/jquery/jquery-ui.min.js" charset="utf-8"></script>--%>

</head>

<body>
<div class="container">
    <table class="layui-table">
        <colgroup>
            <col width="30%">
            <col width="60%">
        </colgroup>
        <%--<thead>--%>
        <%--<tr>--%>
            <%--<th>属性名</th>--%>
            <%--<th>属性值</th>--%>
        <%--</tr>--%>
        <%--</thead>--%>
        <tbody class="sortable">
        <tr id="tb1">
            <td>tb1</td>
            <td class="move">move</td>
        </tr>
        <tr id="tb2">
            <td>tb2</td>
            <td class="move">move</td>
        </tr>
        <tr id="tb3">
            <td>tb3</td>
            <td class="move">move</td>
        </tr>
        <tr id="tb4">
            <td>tb4</td>
            <td class="move">move</td>
        </tr>
        <tr id="tb5">
            <td>tb5</td>
            <td class="move">move</td>
        </tr>
        <tr id="tb6">
            <td>tb6</td>
            <td class="move">move</td>
        </tr>
        <!--<tr>-->
        <!--<td>父节点</td>-->
        <!--<td id="tb7">PARENT_ID</td>-->
        <!--</tr>-->
        </tbody>
    </table>
    <button class="btn">提交</button>
</div>
<%--</div>--%>
</body>

</html>
<script>

        $(document).ready(function(){
            var bttn = $('.container .btn');
            var arr = '';
            var sort = $(".sortable").sortable({
                handle: ".move",
                delay: 0,
                cursor: 'move',
                revert: true,
                stop: bttn.click(function (event) {
                    //记录sort后的id顺序数组
                    var arr = $(".sortable").sortable('toArray');
                    console.log(arr);
                    alert("数组:" + arr)
                })
            });
        })




</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值