abstrak:以前不知道什么時候該用window.onload,工作中有時候遇到JS不執(zhí)行,雖然知道頁面沒加載完JS沒有找到對象,以前也只知道把JS移到最后面可以解決,現(xiàn)在知道可以加上window.onload,頁面加載完執(zhí)行,還是基礎(chǔ)知識不太牢固<!doctype html><html> <head> <meta charset="UT
以前不知道什么時候該用window.onload,工作中有時候遇到JS不執(zhí)行,雖然知道頁面沒加載完JS沒有找到對象,以前也只知道把JS移到最后面可以解決,現(xiàn)在知道可以加上window.onload,頁面加載完執(zhí)行,還是基礎(chǔ)知識不太牢固
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus?">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>改變DIV樣式作業(yè)</title>
</head>
<style>
#box{width:100px;height:100px;background:#f00}
</style>
<body>
<div id="box"></div>
<input type="button" value="變寬" onclick='changeWidth()'>
<input type="button" value="變高" onclick='changeHeight()'>
<input type="button" value="變色" onclick='changeBgColor()'>
<input type="button" value="重置" onclick='reset()'>
<input type="button" value="隱藏" onclick='hide()'>
<input type="button" value="顯示" onclick='show()'>
<script>
var box = document.getElementById('box');
function changeWidth(){
box.style.width='400px';
}
function changeHeight(){
box.style.height='400px';
}
function changeBgColor(){
box.style.backgroundColor='pink'
}
function reset(){
box.style.width='100px';
box.style.height='100px';
box.style.backgroundColor='red'
}
function hide(){
box.style.display='none';
}
function show(){
box.style.display='block';
}
</script>
</body>
</html>
Guru membetulkan:滅絕師太Masa pembetulan:2018-12-19 09:39:34
Rumusan guru:知識點不牢固的話,多練習(xí)就可以啦完成的不錯,繼續(xù)加油