我的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 'quirks'
。错误
每次滚动时都会在控制台上打印未捕获的TypeError:无法读取属性' body'未定义的
。然而,当我在控制台中输入document.body
时,控制台中显示的元素不是undefined
。我也尝试将window.onscroll
移到j Query(function ( $ )
之外,但我得到同样的错误。