专注前端素材!
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>素材8网教程(study.sucai8.cn)</title> </head> <body> <p>点击按钮填充 “Runoob” 到数组的最后两个元素。</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <p><strong>注意:</strong> IE 11 及更早版本不支持 fill() 方法。</p> <script> var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.getElementById("demo").innerHTML = fruits; function myFunction() { document.getElementById("demo").innerHTML = fruits.fill("Runoob",2,4); } </script> </body> </html>
运行结果