我正在尝试让一个每2秒刷新的div在刷新后停止回到顶部。我有PHP代码和JavaScript。我正在使用的JavaScript代码是:
function at_Ticket_scrollBottom()
{
var objDiv = document.getElementById("cartTicket");
objDiv.scrollTop = objDiv.scrollHeight;
}
function at_Tabs_Update()
{
if(div_WPOSVar_IsVisible())
{
//calling setTimeout without clearing any existing timeout can add multiple calls.
//IE the normal 2 second sequence, then call at_Tabs_Update two more times, and
// now we have 3 timeouts set to call at_Tabs again, etc.
//This wouldn't be an issue except that we call at_Tabs_Update directly to cause
// immediate refresh from many places.
//So clear the handle everytime to get rid of the last one we set.
clearTimeout(at_Tabs_Timer);
at_Tabs_Timer=setTimeout("at_Tabs_Update()", 2*1000); //every 2 seconds
return;
}
}
在刷新后,如果我向下滚动到票据底部,在下一次刷新后它会跳回到顶部,因此我永远无法在刷新之前到达底部并选择一个项目进行编辑。如何停止自动滚动回顶部。
setTimeout
-- 传递函数引用:setTimeout(at_Tabs_Update, 2000);
=== 正确做法 - Chris Baker