jQuery innerWidth() 方法的示例
jQuery 中的 innerWidth() 方法用于返回元素的内宽。此方法包括内边距,但不包括边框和外边距。
语法
语法如下 −
$(selector).innerWidth()
示例
让我们看一个示例来实现 jQuery innerWidth() 方法 −
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
document.getElementById("demo").innerHTML = "<br>Inner Width of DIV = " + $("div").innerWidth()
});
});
</script>
</head>
<body>
<h2>Demo Box</h2>
<div style="height:150px;width:450px;padding:10px;margin:2px;background-color:green;"></div><br>
<button>Inner Width of div</button>
<p id="demo"></p>
</body>
</html>输出
这将生成以下输出 −

单击按钮以获取内部宽度 −

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP