题解 | #列表内容排序再渲染#
列表内容排序再渲染
https://www.nowcoder.com/practice/2dffcb354a484995894655a5547b0b49
function sortAndReturnTextContent() {
const items = document.getElementById('myList').children;
const parent = document.getElementById('myList')
//冒泡排序
for (let i = 0; i < items.length; i++) {
for (let j = 0; j < items.length - 1; j++) {
//拿到数字 比较 2 > 1?
if (items[j].textContent.match(/[0-9]/g)[0] > items[j + 1].textContent.match(/[0-9]/g)[0]) {
//交换两个dom节点的位置
parent.insertBefore(items[j + 1], items[j])
}
}
}
}
man,what can i say