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>
原文地址:https://www.cnblogs.com/xinlvtian/p/7874633.html