用原生js实现,点击一个列表时,输出对应的索引
var ul = document.querySelector("ul");
ul.addEventListener("mousedown", mouseHandler);
function mouseHandler(e) {
e.preventDefault();
if (e.target.nodeName !== "LI") return;
var arr = Array.from(ul.children);
var index = arr.indexOf(e.target);
console.log(index);
}