Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我会得到;未捕获类型错误:无法读取属性';车身';“未定义”的定义;?_Javascript_Jquery_Dom_Javascript Events_Event Handling - Fatal编程技术网

Javascript 为什么我会得到;未捕获类型错误:无法读取属性';车身';“未定义”的定义;?

Javascript 为什么我会得到;未捕获类型错误:无法读取属性';车身';“未定义”的定义;?,javascript,jquery,dom,javascript-events,event-handling,Javascript,Jquery,Dom,Javascript Events,Event Handling,我的JS文件很简单 jQuery(function ( $ ) { // make elements with class 'same-height-as-width' have the self-explanatory property $(window).resize(function ( ) { $('.same-height-as-width').each( function ( ) { var thisElement = $(th

我的JS文件很简单

jQuery(function ( $ ) {
    // make elements with class 'same-height-as-width' have the self-explanatory property
    $(window).resize(function ( ) {
        $('.same-height-as-width').each( function ( ) {
            var thisElement = $(this);
            thisElement.height(thisElement.width());        
        });
    });

    window.onscroll = function () {

        var body = document.body; //IE 'quirks'
        var document = document.documentElement; //IE with doctype
        document = (document.clientHeight) ? document : body;

        if (document.scrollTop == 0) {
            alert("top");
        }
    };

});
给我带来麻烦的行是
var body=document.body//IE“怪癖”
。错误

未捕获的TypeError:无法读取未定义的属性“body”


每次滚动时都会打印到控制台。然而,当我在控制台中键入
document.body
时,元素显示在控制台中,而不是
未定义的
。我也尝试过移动
窗口。onscroll
在j
查询(函数($)
之外,但我得到了相同的错误。

这是因为,但不会让您太困惑,不要使用“document”作为变量的名称,因为您可以使用CSS使某个变量的高度与其宽度相同(不知道宽度)即使是现在,我也会非常感激的。看到这个答案了吗