classname在JavaScript中的应用

<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
    #div1 {
        width: 100px;
        height: 100px;
        border: 1px solid red;
    }
    .box {background:red;}
</style>
<script>
    function bianse(){
        var odiv=document.getElementById('div1');
        odiv.className='box';
    }
</script>
</head>

<body>
<input type="button" value="变色" onClick="bianse()" />
<div id="div1">
    
</div>
</body>
</html>
posted @ 2017-11-21 18:06  绿林豪士  阅读(194)  评论(0编辑  收藏  举报