//实现功能:点击哪个 <li>就移动到第一个
function setup() {
var lis = document.querySelectorAll('ul li');
for (var i = 0; i < lis.length; i++) {
lis[i].addEventListener('click', function(e) {
//下面两句有错, 该怎么写?
parent = lis[i].parentNode;
parent.insertBefore(lis[i], lis[0])
});
}
}
// Example case.
document.body.innerHTML = `
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>`;
setup();
document.getElementsByTagName("li")[1].click();
console.log(document.body.innerHTML);
--
FROM 61.171.205.*