码迷,mamicode.com
首页 > 编程语言 > 详细

自定义属性,匹配数组内容——JS学习笔记2015-5-26(第39天)

时间:2015-05-27 00:51:51      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

使用自定义属性匹配数组内容

 

 1 <!DOCTYPE HTML>
 2 <html>
 3 <head>
 4 <title>匹配数组内容</title>
 5 <meta charset="utf-8">
 6 <script>
 7     window.onload = function(){
 8       var aBtn=document.getElementsByTagName(input);
 9       var arr = [A,B,C,D];
10       
11       for(var i=0; i<aBtn.length; i++){
12             aBtn[i].num = 0;
13 
14             aBtn[i].onclick = function(){
15               this.value = arr[this.num]; // 不是arr[i] 理解
16               this.num++;
17               if(this.num===arr.length){
18                    this.num = 0;
19               }
20             }
21        }
22         
23   }
24   
25 </script>
26 </head>
27 
28 <body>
29 <input type="button" value="0"><input type="button" value="0"><input type="button" value="0">
30 </body>
31 </html>

 

自定义属性,匹配数组内容——JS学习笔记2015-5-26(第39天)

标签:

原文地址:http://www.cnblogs.com/zhangxg/p/4532137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!