用js改变DIV样式小实例

原创 2019-02-01 21:26:01 305
摘要:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>div改变css样式</title><style>#box{width:200px;height: 200px;background: lawn

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>div改变css样式</title>

<style>

#box{width:200px;height: 200px;background: lawngreen; }

</style>

</head>

<body>

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

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

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

<input type="button" value="变圆" onclick="tree()">

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

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

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

<script>

var box

window.onload=function(){

box = document.getElementById('box');

}

function  one(){

box.style="height:500px;"

}

function two(){

box.style="width:500px;"

}

function tree(){

box.style="border-radius:50%;"

}

function four(){

box.style="background:red;"

}

function five(){

box.style="display:none;"

}

function six(){

box.style="dispaly:black;"

}

</script>

</body>

</html>


批改老师:天蓬老师批改时间:2019-02-02 11:54:40
老师总结:其实 style 的值也是一个对象, 所以可以直接对它的属性进行操作, 这个要注意, 它与其它属性的值是不同类型

发布手记

热门词条