数组接力棒
数组接力棒
点击一次 按钮,数组的第一项跑到最后,然后删除第一项
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 "http://www.w3.org/TR/html4/strict.dtd"> 3 4 <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 7 <title>1.数组接力棒</title> 8 <meta name="author" content="Administrator" /> 9 <!-- Date: 2014-12-16 --> 10 <script> 11 window.onload=function(){ 12 var oInput=document.getElementsByTagName('input')[0]; 13 var oDiv1=document.getElementById('div1'); 14 var arr=[]; 15 arr=oDiv1.innerHTML.split(','); 16 oInput.onclick=function(){ 17 arr.push(arr[0]); 18 arr.shift(arr[0]); 19 oDiv1.innerHTML=arr//可以直接这样用,也可以用arr.join(',') 20 } 21 } 22 </script> 23 </head> 24 <body> 25 <input type="button" value="点击"> 26 <div id="div1">1,2,3,4</div> 27 </body> 28 </html>