摘要:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml&quo
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>changeDIV</title>
<style type="text/css">
#box{
width: 100px;
height: 100px;
background: red;
margin-top: 20px;
margin-right: 80px;
margin-left: 80px;
}
</style>
</head>
<body>
<!-- 用按鈕控制DIV高度 顏色 重置 隱藏 顯示
-->
<div id="box">
</div>
<br>
<script type="text/javascript">
var box
window.onload=function(){
box=document.getElementById("box")
}
function aa(){
box.style.height="200px"} //改變高度
function bb(){
box.style.width="200px"} //寬度
function cc(){
box.style.background="pink"} //顏色
function dd(){
box.style.height="100px"
box.style.width="100px"
box.style.background="red"
}
function ee(){
box.style.display="none"}
function ff(){
box.style.display="block"}
</script>
<input type="button" value="變高" onclick="aa()">
<input type="button" value="變寬" onclick="bb()">
<input type="button" value="變色" onclick="cc()">
<input type="button" value="重置" onclick="dd()">
<input type="button" value="隱藏" onclick="ee()">
<input type="button" value="顯示" onclick="ff()">
<!--
總結(jié)
函數(shù)是可重復(fù)使用的代碼塊。
function 函數(shù)名(){
執(zhí)行代碼
}
改變CSS 樣式
語法 document.getElementById(id).style.屬性名=”屬性值“
css hidden{display:none;} 隱藏
{display:block;} 顯示
-->
</body>
</html>
批改老師:滅絕師太批改時(shí)間:2018-12-26 09:15:06
老師總結(jié):這是一個(gè)非常簡(jiǎn)單的js小案例,自己可以拓展點(diǎn)課外案例練習(xí)奧!