js中事件的3要素
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
#demo {
width: 200px;
height: 200px;
background-color: pink;
}
</style>
</head>
<body>
<div id="demo"></div>
<button id="btn">改变宽度</button>
<script>
/*要操作先找人*/
var demo = document.getElementById("demo"); //获得id为demo的div盒子给demo
var btn = document.getElementById("btn"); // 获得按钮
/*事件三要素*/
/*事件源.事件 = fucntion(){}*/
btn.onclick = function(){
console.log(this); // this表示btn
demo.style.width = "400px";
}
</script>
</body>
</html>