定义三个按钮
点击按钮,出现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 = 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="0" /> 32 <input type="button" value="0" /> 33 <input type="button" value="0" /> 34 35 </body> 36 </html>
示例代码
时间: 2024-10-10 05:57:38