按照课程讲解重新敲代码,控制正方形的大小,颜色,显示隐藏

原创 2018-12-29 10:42:01 291
摘要:代码<!DOCTYPE html><html><head><meta charset="UTF-8"><title>变化DIV</title><style>#box {height: 100px;width: 100px;background: red;margin: 20px 60px;}&l

代码

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>变化DIV</title>

<style>

#box {height: 100px;width: 100px;background: red;margin: 20px 60px;}

</style>

</head>

<body>

<script type="text/javascript">

var box

window.onload=function () {

box=document.getElementById('box')

}

function aa() {

box.style.height="300px"

}

function bb() {

box.style.width="300px"

}

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>

<div id="box"></div>

<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()">




</body>

</html>


批改老师:天蓬老师批改时间:2018-12-29 10:48:24
老师总结:页面呈现分为二步: html解析与javascript代码执行, 注意一下这二者之间的切换

发布手记

热门词条