<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script> function change(){ var div=document.getElementById("div1");/*w和h都要用这部分,故单独定义一个div*/ var w=parseInt(div.style.width); var h=parseInt(div.style.height); div.style.width=(w+30)+"px"; div.style.height=(h+50)+"px"; } </script> </head> <body> <div id="div1" style="width: 150px;height: 123px;background-color: aqua"></div> <!--设置div初始状态--> <button οnclick="change()">改变样式</button> </body> </html>
点击后: