[JavaScript] jQuery获取指定元素的宽度和高度 →→→→→进入此内容的聊天室

来自 , 2021-04-03, 写在 JavaScript, 查看 149 次.
URL http://www.code666.cn/view/d30d0f52
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
  5. </script>
  6. <script>
  7. $(document).ready(function(){
  8.   $("button").click(function(){
  9.     var txt="";
  10.     txt+="Width of div: " + $("#div1").width() + "</br>";
  11.     txt+="Height of div: " + $("#div1").height();
  12.     $("#div1").html(txt);
  13.   });
  14. });
  15. </script>
  16. </head>
  17. <body>
  18.  
  19. <div id="div1" style="height:100px;width:300px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;"></div>
  20. <br>
  21. <button>Display dimensions of div</button>
  22. <p>width() - returns the width of an element.</p>
  23. <p>height() - returns the height of an element.</p>
  24.  
  25. </body>
  26. </html>
  27.  
  28. //javascript/8122

回复 "jQuery获取指定元素的宽度和高度"

这儿你可以回复上面这条便签

captcha