JavaScript控制DIV样式

原创 2019-01-25 13:27:25 304
摘要:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=DIVDIV, initial-scale=1.0"><met

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=DIVDIV, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>JavaScript控制DIV样式</title>

<style type="text/css">

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

</style>

</head>

<body>

<script type="text/javascript">

var box

window.onload=function(){

box=document.getElementById('box')

}

function aa(){

box.style.height="400px"//改变高度

}

function bb(){

box.style.width="400px"//改变宽度

}

function cc(){

box.style.background="red"//变成红色

}

function dd(){

box.style.height="100px"

box.style.width="100px"

box.style.background="pink"

}

function ee(){

box.style.display="none"

}

function ff(){

box.style.display="block"

}

</script>

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

<INPUT type="button" value="变高" onclick=aa()></INPUT>

<INPUT TYPE="button" value="变宽"onclick=bb()></INPUT>

<INPUT TYPE="button" value="变色"onclick=cc()></INPUT>

<INPUT TYPE="button" value="重置"onclick=dd()></INPUT>

<INPUT TYPE="button" value="隐藏"onclick=ee()></INPUT>

<INPUT TYPE="button" value="显示"onclick=ff()></INPUT>

</body>

</html>

批改老师:天蓬老师批改时间:2019-01-25 15:15:45
老师总结:根据html5的标准, 所以html标签,全部采用小写, 以后不要用大写了,尽管不区分

发布手记

热门词条