【文件属性】:
文件名称:在html拖拉,js实现
文件大小:876B
文件格式:RAR
更新时间:2023-02-28 02:43:40
drag ondragover
html拖拉js
<#list menuLi as item>
<#include "./memuLi/${item}.ftl">
#list>
var node = document.querySelector("#szul");
var draging = null;
//使用事件委托,将li的事件委托给ul
node.ondragstart = function (event) {
console.log("拖拽开始");
draging = event.target.parentNode;
}
node.ondragover = function (event) {
event.preventDefault();
var target = event.target.parentNode;
//因为dragover会发生在ul上,所以要判断是不是li
console.log(target.nodeName);
if (target.nodeName === "LI" && target !== draging) {
console.log(target.parentNode.nodeName);
if (_index(draging) < _index(target)) {
target.parentNode.insertBefore(draging, target.nextSibling);
} else {
target.parentNode.insertBefore(draging, target);
}
var newLi=[];
var liList=$("#zhanjiaul > li");
liList.map(function a(index){
newLi.push($(liList[index]).attr("id"));
});
console.log(newLi);
requestAsyncJsonPostFun("/menu/setUserTopMenu"
,{"topMenus" : newLi}
,function(result) {
}
);
}
}
【文件预览】:
拖拉js
----freemarker.txt(1KB)