abstrak:隨堂案例如下:<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>Change Div 各種屬性</title> <link rel="shortcut icon" type="image/x-icon&qu
隨堂案例如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Change Div 各種屬性</title>
<link rel="shortcut icon" type="image/x-icon" href="../picture/mi.png">
<link rel="stylesheet" type="text/css" href="../css/css.css">
<style type="text/css">
#box{width: 100px;height: 100px;background: red;margin:5px 20px;}
</style>
</head>
<body>
<!-- 用按鈕控制div高度,寬度,顏色,重置,隱藏,顯示 -->
<div id="box"></div>
<input type="button" value="高度" onclick="change_height()">
<input type="button" value="寬度" onclick="change_width()">
<input type="button" value="顏色" onclick="change_color()">
<input type="button" value="重置" onclick="change_reset()">
<input type="button" value="隱藏" onclick="change_hidden()">
<input type="button" value="顯示" onclick="change_display()">
<script type="text/javascript">
var box;
window.onload = function () {
box=document.getElementById("box")
}
function change_width (){//改變寬度
box.style.width="200px";
}
function change_height (){//改變高度
box.style.height="200px";
}
function change_color (){//改變顏色
box.style.background="pink";
}
function change_reset (){//重置
box.style.width="100px";
box.style.height="100px";
box.style.background="red";
}
function change_hidden (){//隱藏
box.style.display="none";
}
function change_display (){//重新顯示
box.style.display="block";
}
</script>
</body>
</html>
老師您好: 該案例我唯一不明白的地方就是window.onload = function () { box=document.getElementById("box") }
這一塊,這個(gè)window.onload 是什么意思呀?
還有就是這個(gè)函數(shù)沒(méi)有函數(shù)名這樣也可以?
JS中的"."是代表連接的意思嗎?如果是那么"+"不也是連接的意思嗎?
Guru membetulkan:滅絕師太Masa pembetulan:2018-11-26 16:23:15
Rumusan guru:window.onload:加載事件在頁(yè)面內(nèi)容加載完成之后立即執(zhí)行相應(yīng)的函數(shù)
js中的點(diǎn)號(hào)取對(duì)象屬性、方法的意思,不是連接