首页 > 语言 > JavaScript > 正文

jQuery获得包含margin的outerWidth和outerHeight的方法

2024-05-06 16:17:37
字体:
来源:转载
供稿:网友

这篇文章主要介绍了jQuery获得包含margin的outerWidth和outerHeight的方法,涉及jQuery中outerWidth及outerHeight方法的使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了jQuery获得包含margin的outerWidth和outerHeight的方法。分享给大家供大家参考。具体如下:

 

 
  1. <!DOCTYPE html> 
  2. <html> 
  3. <head> 
  4. <script src="js/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. <div id="div1" style="height:100px;width:300px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;"> 
  21. </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. </body> 
  27. </html> 

希望本文所述对大家的jQuery程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选