搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
jQuery 教程
jQuery 操作方法
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>jQuery 获取宽度和高度示例 - 基础教程(div.cn)</title> <head> <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("div").click(function(){ let w = $(this).width(); let h = $(this).height(); $(this).html("DIV的宽度: " + w + "<br>" + "DIV的高度: " + h); }); }); </script> <style> div { width: 300px; height: 100px; margin: 5px; padding: 10px; border: 3px solid lightgreen; background-color: rgba(144, 238, 144, .4); } </style> </head> <body> <div>单击此DIV获取宽度和高度</div> </body> </html>
运行结果