<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script type="text/javascript"src="jquery-3.3.1.min.js"></script> <script> $(document).ready(function(){ $(".width").click(function(){ $("div").width(200); }); $(".height").click(function(){ $("div").height(200); }); // $(".color").click(function(){ // $("div").color("pink"); // }); $(".hide").click(function(){ $("div").hide(); }); $(".show").click(function(){ $("div").show(); }); }); </script> </head> <body> <div style="width: 100px;height: 100px;background: red;"></div><br> <button class="width">变宽</button> <button class="height">变高</button> <!-- <button class="color">变色</button> --> <button class="hide">隐藏</button> <button class="show">显示</button> </body> </html>
把之前JavaScript的案例拿过来试了一下,除了变色没办法改变,其他的都可以做到。