js 简单控制html 样式

Original 2018-11-08 12:02:46 136
abstract:<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>js</title>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js</title>
    <style>
        #box{
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
</head>
<body>
<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()">

<script type="text/javascript">
    var box;
    window.onload = function () {
        box =document.getElementById('box');
    };

    function aa() {
        box.style.width='400px'; //变宽

    }
    function bb() {
        box.style.height='400px';//变高

    }
    function cc() {
        box.style.background='pink'; //更换颜色

    }
    function dd() {
        box.style.display='none'; //隐藏

    }
    function ee() {
        box.style.display='block';

    }
    function ff() {
        box.style.display='block';
        box.style.width='100px';
        box.style.height='100px';
        box.style.background='red';
    }

</script>

</body>
</html>


Correcting teacher:灭绝师太Correction time:2018-11-08 13:24:27
Teacher's summary:完成的不错,只是函数名不要学老师呐,可以用的专业点

Release Notes

Popular Entries