11JavaScript DOM动态添加元素样式

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style type="text/css">
        .cls1{
            height:200px;
            width:300px;
            background-color:green;
        }
    </style>
    <script type="text/javascript"> 
        onload = function () {
            document.getElementById('btn').onclick = function () {
                document.getElementById('dv').className = 'cls1';
            };
        };
    </script>
</head>
<body>
    <input id="btn" type="button" name="name" value="给div添加样式 " />
    <div id="dv"></div>
</body>
</html>

  

posted on 2016-01-07 22:13  努力的活着_在人间  阅读(595)  评论(0)    收藏  举报

导航