我正在尝试在 JS 和 HTML 中构建一个可重新排序的列表。(试图在不使用 jQuery ui 的情况下做到这一点)我似乎无法弄清楚为什么在拖动列表项时只有 dragstart 和 dragend 事件会触发。任何人都知道为什么其他事件没有触发?
<ul>
<li draggable="true" class="drag">1111111</li>
<li draggable="true" class="drag">222222</li>
<li draggable="true" class="drag">333333</li>
<li draggable="true" class="drag">444444</li>
</ul>
<script type="text/javascript">
var drags = document.querySelectorAll('.drag');
[].forEach.call(drags, function(drag) {
drag.addEventListener('dragstart', handleDragStart, false);
drag.addEventListener('dragenter', handleDragEnter, false);
drag.addEventListener('dragover', handleDragOver, false);
drag.addEventListener('dragleave', handleDragLeave, false);
drag.addEventListener('dragend', handleDragEnd, false);
});
function handleDragStart(e){
console.log('handleDragStart');
}
function handleDragEnter(e){
console.log('handleDragEnter');
}
function handleDragOver(e){
console.log('handleDragOver');
}
function handleDragLeave(e){
console.log('handleDragLeave');
}
function handleDragEnd(e){
console.log('handleDragEnd');
}
</script>