<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <style> div{ width: 300px; height: 300px; border:1px solid red; background-color: pink; } .width{ width:100px; } .yellow{ background-color: yellow; } </style></head><body> <input type="button" value="测试改变样式" id="add"> <div id="box" class ="yellow">miaovketang</div><script> var changeStyle = document.getElementById("add"); var box = document.getElementById("box"); changeStyle.onclick = function(){ box.classList.toggle("width"); }</script> </body></html>