abstrak:<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>changeDIV</title> <style type="text/css"> #box{width: 100px; height: 100px; bac
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>changeDIV</title>
<style type="text/css">
#box{width: 100px; height: 100px; background: red; margin: 20px 80px;}
</style>
</head>
<body>
<script type="text/javascript">
var box
window.onload=function () {
box=document.getElementsById('box')
}
function ch() {
box.style.height="400px;"//改變高度
}
function cw() {
box.style.width="400px;"//改變寬度
}
function cc() {
box.style.background="pink"//改變顏色
}
function rese() {
box.style.height"100px"
box.style.width="100px;"
box.style.background="red"
}
function yc() {
box.style.display="none;"
}
function xs() {
box.style.display="block;"
}
</script>
<div id="box"></div>
<input type="button" value="變高" onclick="ch()">
<input type="button" value="變寬" onclick="cw()">
<input type="button" value="變色" onclick="cc()">
<input type="button" value="重置" onclick="rese()">
<input type="button" value="隱藏" onclick="yc()">
<input type="button" value="顯示" onclick="xs()">
</body>
</html>
Guru membetulkan:天蓬老師Masa pembetulan:2019-01-02 07:53:12
Rumusan guru:box.style.height="400px;", div是重要,最通用的元素 , 靈活使用極大的簡(jiǎn)化編程