课后练习-JavaScript控制DIV样式

Original 2019-02-21 16:18:00 193
abstract:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>课后练习-JavaScript控制DIV样式</title> <style type="text/css"> #box{wid
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>课后练习-JavaScript控制DIV样式</title>
<style type="text/css">
#box{width: 100px;height: 100px;background: red;margin:20px 80px;}
</style>
</head>
<body>
<script type="text/javascript">
var box
window.onload=function () {
box=document.getElementById('box');
}
function changeHeight() {
box.style.height="400px";
}
function changeWidth() {
box.style.width="400px";
}
function changeBackgroundColor() {
box.style.background="#4f0";
}
function reset() {
box.style.height="100px";
box.style.width="100px";
box.style.background="red";
}
function hide() {
box.style.display="none";
}
    function show() {
box.style.display="block";
}
</script>
<div id="box"></div>
<input type="button" value="变高" onclick="changeHeight();">
<input type="button" value="变宽" onclick="changeWidth();">
<input type="button" value="变色" onclick="changeBackgroundColor();">
<input type="button" value="重置" onclick="reset();">
<input type="button" value="隐藏" onclick="hide();">
<input type="button" value="显示" onclick="show();">
</body>
</html>


Correcting teacher:韦小宝Correction time:2019-02-21 17:26:44
Teacher's summary:写的很不错 js来控制div的样式还是很灵活的

Release Notes

Popular Entries