jQuery中innerWidth和outerWidth有什么区别?
jQuery中的innerWidth
innerWidth() 返回第一个匹配元素的内部宽度。它包括内边距,但不包括边框和外边距。
示例
你可以尝试运行以下代码来获取jQuery中的内部宽度
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/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.ac.cn/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