<body>
<input type="button" value="点击1">
<input type="button" value="点击2">
<input type="button" value="点击3">
<input type="button" value="点击4">
<input type="button" value="点击5">
<input type="button" value="点击6">
<input type="button" value="点击7">
<input type="button" value="点击8">
<input type="button" value="点击9">
<input type="button" value="点击10">
<script>
let btns = document.querySelectorAll('input')
// 循环遍历点击事件
for (let i = 0; i < btns.length; i++) {
//创建事件监听
btns[i].addEventListener('click', function () {
//把伪数组里面所有的值,把背景颜色设置为空
for (let j = 0; j < btns.length; j++) {
btns[j].style.background = ''
}
//设置当前的颜色为pink
this.style.background = 'pink'
})
}
</script>
</body>