本文介绍如何使用jQuery获取document和window对象的宽度和高度。通过绑定按钮点击事件,利用$(document).width()和$(window).width()等方法分别获取文档与窗口的尺寸,并以弹窗形式展示结果,帮助开发者快速掌握页面尺寸获取技巧。
jQuery获取document和window宽高的实现方法
本文详细介绍利用jQuery获取document和window对象宽度和高度的具体实现方式,供读者参考借鉴。
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
var txt="";
txt+="Document width/height: " + $(document).width();
txt+="x" + $(document).height() + "\n";
txt+="Window width/height: " + $(window).width();
txt+="x" + $(window).height();
alert(txt);
});
});
</script>
</head>
<body>
<button>Display dimensions of document and window</button>
</body>
</html>
希望本文提供的示例对您的jQuery编程实践有所帮助。