day-6.6 数组在判断控制上的巧妙运用(switch5颜色控制案例的数组写法)

switch的判断是数字的时候,可以通过数组的下标达到一样的效果。

1 <script>
2            var oWrap = document.getElementById("wrap"),
3                 a =["pink","yellow","blue","green","red"],
4                 index = 0;
5             oWrap.onclick = function (){
6               this.className = a[index++];
7               index%=5;
8             };
9 </script>

 

posted @ 2018-06-01 23:57  bibiguo  阅读(184)  评论(0)    收藏  举报