Javascript 强制滚动到顶部更新

Javascript 强制滚动到顶部更新,javascript,jquery,html,scrolltop,Javascript,Jquery,Html,Scrolltop,我试图强制我的页面总是在顶部加载。我不知道是要定义刷新还是加载,但我已经尝试了所有方法。我搜索了前面所有的问题,没有一个对我有用。我注册了Chrome和Mozilla。你有什么建议吗?我该怎么办 我尝试了以下方法: 一, 二, 三, 四, 五, 六, 使用设置动画功能 $("html, body").animate({ scrollTop: 0 }, 600); 谢谢,但也不行(在Mozilla或Chrome中不行)试试这个$(文档).load().scrollTop(

我试图强制我的页面总是在顶部加载。我不知道是要定义刷新还是加载,但我已经尝试了所有方法。我搜索了前面所有的问题,没有一个对我有用。我注册了Chrome和Mozilla。你有什么建议吗?我该怎么办

我尝试了以下方法:

一,

二,

三,

四,

五,

六,


使用
设置动画
功能

$("html, body").animate({
            scrollTop: 0
}, 600);

谢谢,但也不行(在Mozilla或Chrome中不行)试试这个<代码>$(文档).load().scrollTop(0)不,这是第一个尝试但不起作用的方法之一。您是否签入
$(文档)。就绪(函数(){
,在加载时将其放入就绪函数?老实说,不,我没有。什么样的警报?有代码示例吗?例如:
$(文档)。就绪(函数(){alert(“hello”);$(窗口).scrollTop(0);});
jQuery('html,body').animate({scrollTop:0},0);
$(window).on('beforeunload', function(){
  $(window).scrollTop(0);
});
$(document).ready(function() {
    if (window.location.hash) { 
        //bind to scroll function
        $(document).scroll( function() {
            var hash = window.location.hash
            var hashName = hash.substring(1, hash.length);
            var element;

            //if element has this id then scroll to it
            if ($(hash).length != 0) {
                element = $(hash);
            }
            //catch cases of links that use anchor name
            else if ($('a[name="' + hashName + '"]').length != 0)
            {
                //just use the first one in case there are multiples
                element = $('a[name="' + hashName + '"]:first');
            }

            //if we have a target then go to it
            if (element != undefined) {
                window.scrollTo(0, element.position().top);
            }
            //unbind the scroll event
            $(document).unbind("scroll");
        });
    }

});
$('a').on('click', function(e) {
 e.preventDefault();
 // do your js stuff
 $(window).scrollTop(0);
});
$("html, body").animate({
            scrollTop: 0
}, 600);
$("html, body").animate({
            scrollTop: 0
}, 600);