[JavaScript] 在JavaScript数组的前面插入若干元素的方法 →→→→→进入此内容的聊天室

来自 , 2019-05-30, 写在 JavaScript, 查看 133 次.
URL http://www.code666.cn/view/00482b9b
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p id="demo">Click the button to add elements to the array.</p>
  6.  
  7. <button onclick="myFunction()">Try it</button>
  8.  
  9. <script>
  10. function myFunction()
  11. {
  12. var fruits = ["Banana", "Orange", "Apple", "Mango"];
  13. fruits.unshift("Lemon","Pineapple");
  14. var x=document.getElementById("demo");
  15. x.innerHTML=fruits;
  16. }
  17. </script>
  18.  
  19. <p><b>Note:</b> The unshift() method does not work properly in Internet Explorer 8 and earlier, the values will be inserted, but the return value will be <em>undefined</em>.</p>
  20.  
  21. </body>
  22. </html>
  23.  
  24.  
  25.  
  26. //javascript/7872

回复 "在JavaScript数组的前面插入若干元素的方法"

这儿你可以回复上面这条便签

captcha