搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
JavaScript 教程
JavaScript基础教程
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>JavaScript 数组方法sort()使用示例 - 基础教程(div.cn)</title> <body> <h1>数组方法sort()</h1> <p>点击按钮对数组进行排序:</p> <button onclick="myFunc()">排序</button> <p id="result"></p> <script> var months = ['March', 'Jan', 'Feb', 'Dec']; document.getElementById('result').innerHTML = months; function myFunc() { document.getElementById('result').innerHTML = months.sort(); } </script> </body> </html>
运行结果