用Jquery实现列表拖拽

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jqueryUI拖动</title>
</head>
<script src="jquery-3.5.0.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<style>
    tr{cursor: pointer;}
</style>
<body>
<table id="sort">
    <thead>
    <tr>
        <th class="index">序号</th>
        <th>年份</th>
        <th>标题</th>
        <th>作者</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td class="index">1</td>
        <td>2014</td>
        <td>这是第1个</td>
        <td>阿斯蒂芬阿斯蒂芬</td>
    </tr>
    <tr>
        <td class="index">2</td>
        <td>2015</td>
        <td>这是第2个</td>
        <td>阿萨德发射点发岁的</td>
    </tr>
    <tr>
        <td class="index">3</td>
        <td>2016</td>
        <td>这是第3个</td>
        <td>阿萨德发送地方</td>
    </tr>
    <tr>
        <td class="index">4</td>
        <td>2017</td>
        <td>这是第4个</td>
        <td>的说法大赛分</td>
    </tr>
    </tbody>
</table>
<script>
    $(document).ready(function(){
        var fixHelperModified = function(e, tr) {
                var $originals = tr.children();
                var $helper = tr.clone();
                $helper.children().each(function(index) {
                    $(this).width($originals.eq(index).width())
                });
                return $helper;
            },
            updateIndex = function(e, ui) {
                $('td.index', ui.item.parent()).each(function (i) {
                    $(this).html(i + 1);
                });
            };
        $("#sort tbody").sortable({
            helper: fixHelperModified,
            stop: updateIndex
        }).disableSelection();
    });
</script>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值