Jquery 为什么可以';我不能滚动到底部吗?

Jquery 为什么可以';我不能滚动到底部吗?,jquery,scroll,Jquery,Scroll,我有一个功能,可以触发滚动到页面的最底部,而不需要动画 function scroll() { $(document).scrollTop(500); } 上述代码有效 function scroll() { $(document).scrollTop($(document).height()); } 为什么上面的代码不起作用…试试这个: $(document).scrollTop(document.body.scrollHeight); 试试这个: $(document).scroll

我有一个功能,可以触发滚动到页面的最底部,而不需要动画

function scroll() {
$(document).scrollTop(500); 
}
上述代码有效

function scroll() {
$(document).scrollTop($(document).height());
}
为什么上面的代码不起作用…

试试这个:

$(document).scrollTop(document.body.scrollHeight);
试试这个:

$(document).scrollTop(document.body.scrollHeight);
用这个

$("html, body").animate({ scrollTop: $(document).height() }, 1000);
也测试

$(document).scrollTop($(document).height());
它很好用

用这个

$("html, body").animate({ scrollTop: $(document).height() }, 1000);
也测试

$(document).scrollTop($(document).height());

它工作正常

正常情况下,上述代码应该可以工作。出于某种奇怪的原因,它不起作用。我这样做:

我有一个创建新id的PHP while循环。然后我使用JS转到一个新URL。例如:

<div class='box' id='1' limit='2'> One </div>
<div class='box'id='2' limit='2'> Two </div>

正常情况下,上述代码应该可以工作。出于某种奇怪的原因,它不起作用。我这样做:

我有一个创建新id的PHP while循环。然后我使用JS转到一个新URL。例如:

<div class='box' id='1' limit='2'> One </div>
<div class='box'id='2' limit='2'> Two </div>

但是它确实可以工作,例如,在这个页面上,如果你在控制台上调用它。尝试首先打印高度:
console.log($(document.height())。你得到了什么?错误?什么是
$(document).height()
输出?您是否检查了它的值?您的代码(上面提到的代码)可能也有错误,因此它永远不会到达这些行。它可以工作并输出1467。您的代码可以工作只是检查了一下,但它确实可以工作,例如,如果您在控制台上调用它,它就可以在本页上工作。尝试首先打印高度:
console.log($(document.height())。你得到了什么?错误?什么是
$(document).height()
输出?您检查过它的值了吗?您的代码上可能还有一个错误,上面提到的代码,因此它永远不会到达这些行。它工作并输出1467。您的代码正在工作,只是检查了一下