Jquery $(窗口).height()返回错误的值

Jquery $(窗口).height()返回错误的值,jquery,wordpress,window,height,Jquery,Wordpress,Window,Height,运行$(window).height()时无法获得正确的值。在所有浏览器中都是一样的 以下是我使用的代码: // Screen height sections $(function() { function screen_height() { $('.screen-height').css({'height': $(window).height() }); } screen_height(); window.addEventListener("

运行
$(window).height()时无法获得正确的值。在所有浏览器中都是一样的

以下是我使用的代码:

// Screen height sections
$(function() {

    function screen_height() {
        $('.screen-height').css({'height': $(window).height() });
    }

    screen_height();
    window.addEventListener("orientationchange", screen_height );
    $(window).resize( screen_height );

});
以下是我尝试过的:

  • 使用正确的doctype声明(
  • 删除相关div中的所有内容
  • 删除js文件中除screen_height函数外的所有内容
  • 删除screen_height函数中除
    $('.screen height').css({'height':$(window.height()})之外的所有内容
  • $(window).height()执行console.log并获得12191作为回报

我被难住了。据我所知,错误发生在网站更新到WordPress 4.0时,但它没有使用WordPress中捆绑的jQuery版本。感谢所有帮助。

当doctype设置不正确时,jQuery将
$(窗口).height()
视为与
$(文档).height()相同

您使用了正确的doctype(
),但通过在其前面添加分析代码,您已使其无效

将您的分析代码移到头部,就在结束标记之前,它应该可以正常工作


编辑:我刚刚注意到您有两个不同的分析代码块。去掉最上面的一个(在第1行)。

为什么不使用
window.outerHeight
window.innerHeight
?此外,您应该将googleanalytics脚本移动到HTML中-当前页面以doctype声明之前的脚本开始,结束时不关闭body和HTML(=结尾处缺失).太棒了,谢谢。分析代码是通过一个插件添加的,我不知道客户端已经安装了这个插件。停用它解决了这个问题。