按降序排列数字
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript 数组排序</h1>
- <p>单击按钮可按降序对数组进行排序。</p>
- <button onclick="myFunction()">试一试</button>
- <p id="demo"></p>
- <script>
- var points = [40, 100, 1, 5, 25, 10];
- document.getElementById("demo").innerHTML = points;
- function myFunction() {
- points.sort(function(a, b){return b - a});
- document.getElementById("demo").innerHTML = points;
- }
- </script>
- </body>
- </html>