亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript控制DIV樣式案例及總結

原創(chuàng) 2018-12-25 20:45:08 263
摘要:<!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()">


<!--  

總結

函數是可重復使用的代碼塊。

function 函數名(){

執(zhí)行代碼

}



改變CSS 樣式

語法 document.getElementById(id).style.屬性名=”屬性值“


css hidden{display:none;}  隱藏

           {display:block;} 顯示

-->





</body>

</html>


批改老師:滅絕師太批改時間:2018-12-26 09:15:06
老師總結:這是一個非常簡單的js小案例,自己可以拓展點課外案例練習奧!

發(fā)佈手記

熱門詞條