jQuery中innerWidth和outerWidth有什麼區別?
jQuery中的innerWidth
innerWidth() 返回第一個匹配元素的內部寬度。它包括內邊距,但不包括邊框和外邊距。
示例
你可以嘗試執行以下程式碼來獲取jQuery中的內部寬度
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert("Inner Width of div element: " + $("div").innerWidth());
});
});
</script>
</head>
<body>
<div style="height:200px;width:500px;padding:20px;margin:1px;border:1px solid red; background-color:gray;"></div><br>
<button>Get Inner Width of div</button>
</body>
</html>
jQuery中的outerWidth
outerWidth() 返回第一個匹配元素的外部寬度。它包括內邊距和邊框。
示例
你可以嘗試執行以下程式碼來獲取jQuery中的外部寬度
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert("Outer Width of div element: " + $("div").outerWidth());
});
});
</script>
</head>
<body>
<div style="height:200px;width:500px;padding:20px;margin:1px;border:1px solid red; background-color:gray;"></div><br>
<button>Get Outer Width of div</button>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP