源代码 :
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>开源教程(ossoft.cn)</title> </head> <body> <p id="demo">单击按钮删除数组的第一个元素。</p> <p id="demo2"></p> <button onclick="myFunction()">点我</button> <script> var fruits = ["Banana", "Orange", "Apple", "Mango"]; function myFunction(){ var delell = fruits.shift(); var x=document.getElementById("demo"); x.innerHTML= '删除后数组为:' + fruits; document.getElementById("demo2").innerHTML= '删除的元素是:' + delell; } </script> </body> </html>
运行结果