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://meitianjinbu.cn/