源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <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 0.5 - Math.random()}); document.getElementById("demo").innerHTML = points; } </script> </body> </html>
运行结果