jquery在更新面板中滚动页面到页面顶部的问题

Issue in jquery scrolling page to top of the page in update panel

本文关键字:顶部 问题 更新 jquery 滚动      更新时间:2023-09-26

我在aspx页面中使用更新面板,我希望每当页面部分加载时,页面应该在页面顶部滚动。我把jquery写成

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
    // re-bind your jQuery events here
    this.window.scrollTo(0, 0);
    alert("helloo");
});

上面的jquery不工作!!请帮助! !

很可能,您的脚本包含在UpdatePanel内容之外。在更新面板中包含脚本。

另外,考虑将执行滚动的命令更改为:

 $("html, body").scrollTop(0);
 $("html, body").scrollLeft(0);