abstrak:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">&
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>js控制div</title>
<style>
#box{height: 100px;width: 100px;background-color: aquamarine;
margin: 30px 50px; }
</style>
</head>
<body>
<div id='box'></div>
<input type="button" value="變高" onclick="hight()">
<input type="button" value="變寬" onclick="wide()">
<input type="button" value="變色" onclick="color()">
<input type="button" value="重置" onclick="reset()">
<input type="button" value="隱藏" onclick="hide()">
<input type="button" value="顯示" onclick="display()">
<input type="button" value="變圓" onclick="circle()">
<script>
var box;
window.onload=function(){
box=document.getElementById('box');
}
function hight(){
box.style.height="400px";//改變高度
}
function wide(){
box.style.width='400px';//改變寬度
}
function color(){
box.style.backgroundColor="red";//改變背景色
}
function reset(){
box.style.height="100px";//重置樣式
box.style.width="100px";
box.style.backgroundColor="aquamarine";
}
function hide(){
box.style.display="none";//隱藏樣式
}
function display(){
box.style.display="block";//顯示樣式
}
function circle(){
box.style.borderRadius="50%";//改變圓形
}
</script>
</body>
</html>
Guru membetulkan:韋小寶Masa pembetulan:2019-02-21 13:59:37
Rumusan guru:通過js來動態(tài)的修改div的樣式還可以做成動畫的效果 從而讓頁面更有活力