jQuery的innerWidth()示例
innerWidth是jQuery内置的一个方法,用于返回第一个匹配元素的宽度。
语法:
$(selector).innerWidth()
这里的选择器是指选定的元素。
参数:它不接受任何参数。
返回值:它返回选择器的宽度。
jQuery代码显示innerWidth()方法的工作:
<!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script>
<!--jQuery code to demonstrate innerWidth function -->
// document ready
(document).ready(function() {
// on clicking the paragraph
("p").click(function() {
// innerWidth
document.getElementById("demo").innerHTML = "innerWidth = "
+ $("div").innerWidth();
});
});
</script>
</head>
<body>
<div style="height: 100px;width: 200px; background-color: blue">
</div>
<p>Click here to know innerWidth</p>
<p id="demo"></p>
</body>
</html>