[JavaScript] jQuery获得包含margin的outerWidth和outerHeight →→→→→进入此内容的聊天室

来自 , 2020-07-05, 写在 JavaScript, 查看 110 次.
URL http://www.code666.cn/view/1b742ae2
  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() + "</br>";
  12.     txt+="Outer width of div (margin included): " + $("#div1").outerWidth(true) + "</br>";
  13.     txt+="Outer height of div (margin included): " + $("#div1").outerHeight(true);
  14.     $("#div1").html(txt);
  15.   });
  16. });
  17. </script>
  18. </head>
  19. <body>
  20.  
  21. <div id="div1" style="height:100px;width:300px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;"></div>
  22. <br>
  23. <button>Display dimensions of div</button>
  24. <p>outerWidth(true) - returns the width of an element (includes padding, border, and margin).</p>
  25. <p>outerHeight(true) - returns the height of an element (includes padding, border, and margin).</p>
  26.  
  27. </body>
  28. </html>
  29.  
  30. //javascript/8125

回复 "jQuery获得包含margin的outerWidth和outerHeight"

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

captcha