点击前
点击后
<!DOCTYPE html>
<html lang="en">
<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>
</head>
<style>
div {
width: 100px;
height: 200px;
background-color: red;
}
</style>
<body>
<div></div>
<script>
//第一步 获取元素
var div = document.querySelector('div')
div.onclick = function(){
this.style.width = '200px'
this.style.backgroundColor='black'
}
</script>
</body>
</html>