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

js改變div樣式

原創(chuàng) 2018-12-03 11:22:49 366
摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>js控制div樣式</title> <style type="text/css"> #box{ w
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>js控制div樣式</title>
		<style type="text/css">
			#box{
				width: 100px;
				height: 100px;
				background: red;
				margin: 20px 80px;
			}
		</style>
	</head>
	<body>
		<div id="box"></div>
		<input type="button" name="" id="" value="改變高度" onclick="change(value)"/>
		<input type="button" name="" id="" value="改變寬度" onclick="change(value)"/>
		<input type="button" name="" id="" value="改變顏色" onclick="change(value)"/>
		<input type="button" name="" id="" value="重置" onclick="change(value)"/>
		<input type="button" name="" id="" value="隱藏" onclick="change(value)"/>
		<input type="button" name="" id="" value="顯示" onclick="change(value)"/>
		<script type="text/javascript">
			var box=document.getElementById("box");
			function change (value) {
				if (value=="改變高度") {
					box.style.height="400px";
				} else if(value=="改變寬度"){
					box.style.width="400px";
				} else if (value=="改變顏色") {
					box.style.backgroundColor="pink";
				} else if(value=="重置"){
					box.style.height="100px";
					box.style.width="100px";
					box.style.background="red";
				} else if (value=="隱藏") {
					box.style.display="none";
				} else if (value=="顯示") {
					box.style.display="block";
				}
			}

		</script>
	</body>
</html>


批改老師:天蓬老師批改時(shí)間:2018-12-03 13:45:54
老師總結(jié):用事件偵聽(tīng)器,改寫(xiě)一下這個(gè)案例, addEventListener(), 試試看

發(fā)布手記

熱門(mén)詞條