<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>点击切换abcd</title>
</head>
<body>
<input type="button" value="0"></input>
<input type="button" value="0"></input>
<input type="button" value="0"></input>
</body>
</html>
<script>
var aIn=document.getElementsByTagName('input');
var arr=['a','b','c','d'];
for(var i=0;i<aIn.length;i++){ //遍历按钮
aIn[i].num=0; //自定义属性num为0
aIn[i].οnclick=function(){
this.value=arr[this.num];//将数组中的内容放在value
this.num++; //增加this的num值
if(this.num==arr.length){ //如果大于数组长度 那么为零重新开始
this.num=0;
};
}
}
</script>
获取自身递增数字及匹配数组内容
最新推荐文章于 2021-05-07 18:03:33 发布