<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Examples</title> <meta name="description" content=""> <meta name="keywords" content=""> <link href="" rel="stylesheet"> <script> window.onload=function(){ var oBtn=document.getElementById("btn1"); var oUl=document.getElementById("ul1"); var oLi=document.getElementsByTagName("li"); oBtn.onclick=function(){ var arr=[]; for(var i=0;i<oLi.length;i++){ arr[i]=oLi[i]; } arr.sort(function(li1,li2){ var n1=parseInt(li1.innerHTML); var n2=parseInt(li2.innerHTML); return n1-n2; }); for(var j=0;j<arr.length;j++){ oUl.appendChild(arr[j]); } } } </script> </head> <body> <input type="button" value="排序" id="btn1"> <ul id="ul1"> <li>3</li> <li>55</li> <li>32</li> <li>22</li> <li>87</li> <li>57</li> <li>33</li> <li>2</li> </ul> </body> </html>