<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
background-color: gold;
}
</style>
</head>
<body>
<button>按钮</button>
<button>按钮</button>
<button>按钮</button>
<button>按钮</button>
<button>按钮</button>
<button class="first">按钮</button>
<script>
let btn = document.querySelectorAll('button')
for (let i = 0; i < btn.length; i++) {
btn[i].addEventListener('click', function () {
this.style.border = "5px solid red " // 适合修改一个属性
this.style.width = "100px"
// cssText : 可以一次修改多个属性
this.style.cssText = 'width:200px ; height:200px;'
// className : 先写好类名,直接调用类名
this.className = "box"
})
}
</script>
</body>
</html>