标签:index nts cti put body var btn 属性 type
<script>
window.onload = function (){
var aBtn = document.getElementsByTagName(‘input‘);
for( var i=0; i<aBtn.length; i++ ){
aBtn[i].index = i; // 自定义属性(索引值)
aBtn[i].onclick = function (){
// alert( i ); // 3
alert( this.index );
};
}
};
</script>
</head>
<body>
<input type="button" value="btn1" />
<input type="button" value="btn2" />
<input type="button" value="btn3" />
标签:index nts cti put body var btn 属性 type
原文地址:https://www.cnblogs.com/tongguilin/p/12193569.html