gpt4 book ai didi

javascript - jquery警报($ ("window").height() + ""+ $ ("document").height() + ""+$ ("window").width());将所有值返回为 null

转载 作者:行者123 更新时间:2023-11-28 15:33:10 25 4
gpt4 key购买 nike

我正在尝试获取浏览器窗口的高度和宽度,因此它返回 null 示例代码如下我还使用了在 stackoverflow 中找到的 $("window").load(function()) ,但它仍然返回 null。

<html>
<head></head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></scipt>
<script>
$(document).ready(function(){
//$("#page").outerWidth($("window").width(),true);
// $("#page").outerHeight($("window").height(),true);
alert($("window").height() + " " + $("document").height() + " " +$("window").width());
});
</script>
</body>
</html>

最佳答案

$("window") 应为 $(window)

当您使用 $("window") 时,您要求 jQuery 选择所有带有 tagName“window”的元素(但实际上没有)。当您使用 $(window) 时,您实际上是在告诉 jQuery 包装 window 对象。

而且,需要明确的是,这也适用于 $("document")$(document) 的更改。

关于javascript - jquery警报($ ("window").height() + ""+ $ ("document").height() + ""+$ ("window").width());将所有值返回为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26391522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com