<!DOCTYPE >
<html>
<head>
<title></title>
<meta charset="utf-8">
<script>
window.onload = function() {
var oBtn = document.getElementById('order');
oBtn.onclick = function() {
var oUL = document.getElementById('ul1');
var oLi = oUL.getElementsByTagName('li');
var arr = [];
for(var i = 0; i < oLi.length; i++) {
arr[i] = oLi[i];
}
arr.sort(function(l1, l2) {
var n1 = parseInt(l1.innerHTML);
var n2 = parseInt(l2.innerHTML);
return n1 - n2;
})
for(var i = 0; i < oLi.length; i++) {
oUL.appendChild(arr[i]);
}
}
}
</script>
</head>
<body>
<input type="button" name="order" id="order" value="排序" />
<ul id="ul1">
<li>2</li>
<li>4</li>
<li>5</li>
<li>1</li>
<li>3</li>
<li>6</li>
</ul>
</body>
</html>
image.png