div的js操作style

原创 2019-01-18 12:17:32 441
摘要:<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Document</title><style type="text/css">div{width:200px;height:200px;background-col

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<style type="text/css">

div{width:200px;height:200px;background-color: blue;}

</style>

<script type="text/javascript">

var box

window.onload=function(){

box = document.getElementById('cc');

}

function h(){

box.style.height="400px";

}

function w(){

box.style.width="400px";

}

function c(){

box.style.backgroundColor = 'red';

}

function z(){

box.style.width="100px";

box.style.height="100px";

box.style.backgroundColor = 'blue'

}

function y(){

box.style.display="none";

}

function d(){

box.style.display="block";

}

</script>

</head>

<body>

<div id="cc"></div>

<input type="button" name="" value="变高" onclick="h()">

<input type="button" name="" value="变宽" onclick="w()" >

<input type="button" name="" value="变色"  onclick="c()">

<input type="button" name="" value="重置" onclick="z()">

<input type="button" name="" value="隐藏" onclick="y()">

<input type="button" name="" value="显示" onclick="d()">

</body>

</html>


批改老师:灭绝师太批改时间:2019-01-18 13:13:01
老师总结:完成的不错,案例除了老师上课代码,还可以自己拓展哦!

发布手记

热门词条