????:代碼如下:<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Document</title><style type="text/css">#box{width: 100px;height: 100px;backgr
代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
#box{width: 100px;height: 100px;background-color:red; margin: 50px 80px;}
</style>
</head>
<body>
<div id="box"></div>
<input type="button" value="變高" onclick="hei()">
<input type="button" value="變寬" onclick="wid()">
<input type="button" value="變色" onclick="col()">
<input type="button" value="重置" onclick="res()">
<input type="button" value="隱藏" onclick="hid()">
<input type="button" value="顯示" onclick="dis()">
<script type="text/javascript">
var box
window.onload=function () {
box=document.getElementById('box')
}
function hei() {
box.style.height="500px"
}
function wid() {
box.style.width="500px"
}
function col() {
box.style.background="green"
}
function res() {
box.style.height="100px"
box.style.width="100px"
box.style.background="red"
}
function hid() {
box.style.display="none"
}
function dis() {
box.style.display="block"
}
</script>
</body>
</html>
總結(jié):復(fù)習(xí)了函數(shù)的定義,變量的聲明,函數(shù)的執(zhí)行
1、定義函數(shù)用function 函數(shù)名稱(){ 函數(shù)體}
2、window.onload=function(){}: 表示頁(yè)面加載完成時(shí)加載函數(shù)
3、onclick=“函數(shù)名稱()”單擊時(shí)執(zhí)行函數(shù)
?? ???:滅絕師太?? ??:2019-01-03 09:11:15
???? ??:onclick=“函數(shù)名稱()”單擊時(shí)執(zhí)行函數(shù)(這是一個(gè)匿名函數(shù)奧!)完成的不錯(cuò),繼續(xù)加油!