更新了HBuilder X之后Sortable插件报错

点了下软件更新。上个厕所回来插件报错了

<script src="Sortable.js"></script>
        <script src="jquery.js"></script>
<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>
 <script>
        /////////初始滑动插件
        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>

之前还能正常运行

img


插件报错

img

在你的另一个问题下已经做出过回答了,这个错误是执行js时dom还没加载完成导致的,这时候foo是null
你另一个问题的链接
https://ask.csdn.net/questions/7698677?spm=1001.2014.3001.5505
如有帮助请采纳回答~