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