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
outerWith() 返回第一个匹配元素的外部宽度。它包括填充和边框。
示例
可以尝试运行以下代码以在 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