App下載
實(shí)例代碼( Tip: 登錄后體驗(yàn)更佳 )
運(yùn)行結(jié)果
<!DOCTYPE html> <html> <head> <meta charset=\"utf-8\"> <script src=\"http://libs.baidu.com/jquery/1.10.2/jquery.min.js\"> </script> <script> $(document).ready(function(){ $(\"button\").click(function(){ var txt=\"\"; txt+=\"div 寬度: \" + $(\"#div1\").width() + \"</br>\"; txt+=\"div 高度: \" + $(\"#div1\").height() + \"</br>\"; txt+=\"div 寬度,包含內(nèi)邊距和邊框: \" + $(\"#div1\").outerWidth() + \"</br>\"; txt+=\"div 高度,包含內(nèi)邊距和邊框: \" + $(\"#div1\").outerHeight(); $(\"#div1\").html(txt); }); }); </script> </head> <body> <div id=\"div1\" style=\"height:100px;width:300px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;\"></div> <br> <button>顯示 div 元素的尺寸</button> <p>outerWidth() - 返回元素的寬度 (包含內(nèi)邊距和邊框)。</p> <p>outerHeight() - 返回元素的高度 (包含內(nèi)邊距和邊框)。</p> </body> </html>