jQuery获得包含margin的outerWidth和outerHeight的方法教程
程序员文章站
2022-07-01 15:25:32
本文实例讲述了jquery获得包含margin的outerwidth和outerheight的方法。分享给大家供大家参考。具体如下:
本文实例讲述了jquery获得包含margin的outerwidth和outerheight的方法。分享给大家供大家参考。具体如下:
<!doctype html> <html> <head> <script src="js/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ var txt=""; txt+="width of p: " + $("#p1").width() + "</br>"; txt+="height of p: " + $("#p1").height() + "</br>"; txt+="outer width of p (margin included): " + $("#p1").outerwidth(true) + "</br>"; txt+="outer height of p (margin included): " + $("#p1").outerheight(true); $("#p1").html(txt); }); }); </script> </head> <body> <p id="p1" style="height:100px;width:300px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;"> </p> <br> <button>display dimensions of p</button> <p>outerwidth(true) - returns the width of an element (includes padding, border, and margin).</p> <p>outerheight(true) - returns the height of an element (includes padding, border, and margin).</p> </body> </html>
上一篇: SpringMVC
下一篇: 汽车品牌写情书(有才)