js动态改变样式属性(className属性)

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>className属性</title>


    <style type="text/css">
        .myDiv{
            height: 50px;
            width: 50px;
            border: 1px solid red;
        }
        .newStyle{
            height: 150px;
            width: 150px;
            border: 2px solid pink;
        }
    </style>
</head>
<body>

<div class="myDiv" id="myDiv"></div>


<script type="text/javascript">
     var div= document.getElementById("myDiv");
     div.onclick=function(){
         div.className="newStyle";  //newStyle是我们需要设置class的名称
     }
</script>
</body>
</html>

 

posted @ 2017-11-02 22:33  亲亲的我来了  阅读(1353)  评论(0编辑  收藏  举报