html代码:
<input type="button" value="修改样式" id="gai">
<div class="box"></div>
js代码:
<script>
// 找到div
var box = document.getElementsByClassName('box')[0];
// 找到按钮,添加点击事件
document.getElementById('gai').onclick = function () {
box.style.width = "500px";
box.style.height = "500px";
box.style.backgroundColor = "red";
box.style.opacity = 0.5;
box.style.marginTop = "10px";
}
</script>