jquery包括margin外边距的outerWidth或者outerHeight
分类:实例代码
本章节分享一段代码实例,它实现了获取包括外边距在内的outerWidth或者outerHeight效果。
代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>前端教程网</title> <style> #antzone{ height:100px; width:300px; padding:10px; margin:3px; border:1px solid blue; background-color:lightblue; } </style> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <script> $(document).ready(function(){ $("#bt").click(function(){ var txt=""; txt+="div的宽度:" + $("#antzone").width()+"</br>"; txt+="div的高度:" + $("#antzone").height()+"</br>"; txt+="包括margin的outerWidth:"+$("#antzone").outerWidth(true)+"</br>"; txt+="包括margin的outerHeight:"+$("#antzone").outerHeight(true); $("#antzone").html(txt); }); }); </script> </head> <body> <div id="antzone"></div> <input type="button" id="bt" value="查看效果"/> </body> </html>
outerWidth()方法可以参阅jQuery outerWidth()一章节。
一线大厂高级前端编写,前端初中阶面试题,帮助初学者应聘,需要联系微信:javadudu