jQuery | innerWidth()及其示例

这个 内宽 是jQuery中的一个内置方法,用于返回第一个匹配元素的宽度。 语法:

null
$(selector).innerWidth()

这里的选择器是选定的元素。 参数: 它不接受任何参数。 返回值: 它返回选择器的宽度。 显示innerWidth()方法工作的jQuery代码:

<!DOCTYPE html>
< html >
< head >
< script
</ 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 >


输出: 在点击段落之前- 图片[1]-jQuery | innerWidth()及其示例-yiteyi-C++库

点击段落后- 图片[2]-jQuery | innerWidth()及其示例-yiteyi-C++库

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享