多个按钮,每个按钮每点击一次文字描述根据数组依次变换

var aBtn = document.getElementsByTagName('input');
    var arr = [ 'A', 'B', 'C', 'D' ];    
    for( var i=0; i<aBtn.length; i++ ){        
        aBtn[i].num = 0;        
        aBtn[i].onclick = function (){
            this.value = arr[ this.num ];            
            this.num++;
            if( this.num === arr.length ){
                this.num = 0;
            }
        };
    }
<input type="button" value="0" />
<input type="button" value="0" />
<input type="button" value="0" />

 

posted @ 2017-04-18 11:38  念念念不忘  阅读(193)  评论(0)    收藏  举报