如何使用jQuery获取div元素的宽度?
要获取div元素的宽度,请使用width()jQuery中的方法。
示例
您可以尝试使用jQuery运行以下代码来获取div元素的宽度:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert("Width of div element: " + $("div").width());
});
});
</script>
</head>
<body>
<div style="height:200px;width:450px;padding:20px;margin:1px;border:1px solid red;background-color:gray;"></div><br>
<button>Get Width of div</button>
</body>
</html>热门推荐
10 关于健康的祝福语简短
11 红包祝福语简短10字
12 祝福语简短独特教官
13 自己祝福语简短唯美短句
14 10岁高考祝福语简短
15 2026腊八简短祝福语
16 周末祝福语简短有内涵
17 简短微信祝福语大全
18 妹妹生日祝福语简短好看