首页 > 代码库 > 自定义属性(2)
自定义属性(2)
定义三个按钮
点击按钮,出现A、B、C、D字母,点击一下,出现一个
当按钮字母为 D 的时候,继续点击又会重新回到 A
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>无标题文档</title> 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 13 aBtn[i].num = 0; 14 15 aBtn[i].onclick = function (){ 16 // alert( arr[ this.num ] ); 17 this.value = http://www.mamicode.com/arr[ this.num ]; 18 19 this.num++; 20 if( this.num === arr.length ){ 21 this.num = 0; 22 } 23 }; 24 } 25 }; 26 </script> 27 </head> 28 29 <body> 30 31 <input type="button" value="http://www.mamicode.com/0" /> 32 <input type="button" value="http://www.mamicode.com/0" /> 33 <input type="button" value="http://www.mamicode.com/0" /> 34 35 </body> 36 </html>
自定义属性(2)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。