Darling_lxy 2022-04-23 10:31 采纳率: 71.4%
浏览 1277
已结题

拖拽插件报错Sortable报错Sortable: `el` must be HTMLElement, and not [object Null]

之前还好好的,代码也没有一点改动
然后就报错
Uncaught Sortable: el must be HTMLElement, and not [object Null]

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="Sortable.js"></script>
        <script src="jquery.js"></script>
        <style>
            .sotr {
                width: 500px;
                height: 300px;
                margin: 100px auto 10px;
                border: 1px solid #ddd;
            }

            .sotr a {
                float: left;
                display: block;
                width: 100px;
                height: 100px;
                margin: 10px;
            }

            .click {
                width: 100px;
                height: 100px;
                background: #DDDDDD;
                margin: 0 auto;
                text-align: center;
            }

            .upset {
                width: 100px;
                height: 100px;
                background: #DDDDDD;
                margin: 0px auto;
                text-align: center;
            }
        </style>


    </head>
    <body>
        <div id="sotr" class="sotr">
            <a data-index='0' style="background: #aa0000;">1</a>
            <a data-index='1' style="background: #005500;">2</a>
            <a data-index='2' style="background: #aa5500;">3</a>
            <a data-index='3' style="background: #59d57f;">4</a>
            <a data-index='4' style="background: #00ffff;">5</a>
            <a data-index='5' style="background: #ff007f;">6</a>
            <a data-index='6' style="background: #ffff7f;">7</a>
            <a data-index='7' style="background: #5500ff;">8</a>
        </div>
        <div id="click" class="click">提交</div>
        <div id="upset" class="upset">打乱</div>
    </body>
    <script>
            window.onload = function () {
                /////////初始滑动插件
                var foo = document.getElementById("#sotr");
                Sortable.create(foo, {
                    group: "adva"
                });
     
       
                function shffle() {
                    let array = $('#sotr a')
                    let usedIndex = []
                    let newArray = []
                    let validCount = []
     
                    top:
                    while (validCount < array.length) {
                        let index = Math.floor(Math.random() * array.length)
                        if (usedIndex.indexOf(index) > -1) {
                            continue top
                        } else {
                            usedIndex.push(index)
                        }
                        validCount++
                        newArray.push(array[index])
                    }
                    let newarr = shuffle()
                    for (let item of newarr) {
                        $('#sotr').append(item)
                    }
                }
                $('#upset').on('click', shffle)
          
     }
        </script>



</html>

刚开始还是能把DIV顺序打乱

img

现在没效果了

img

  • 写回答

2条回答 默认 最新

  • 小草的味道 2022-04-23 10:53
    关注

    img


    这个 js 贴出来

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 5月1日
  • 已采纳回答 4月23日
  • 创建了问题 4月23日

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看