<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div{
width: 100px;
height: 100px;
background-color: pink;
}
.new{
position: absolute;
width: 200px;
height: 200px;
left: 200px;
top:200px;
}
</style>
</head>
<body>
<input type="button" value="按钮" id="btn">
<div id="box" </div>
<script>
function my$(id){return document.getElementById(id)};
//获取元素
var btn = my$("btn");
var box = my$("box");
//添加事件
btn.onclick = function (){
//修改类名
// box.className = "new";
//直接修改样式属性
box.style.position = "absolute";
box.style.width = "200px";
box.style.height = "200px";
box.style.left = "200px";
box.style.top = "200px";
}
</script>
</body>
</html>