HTML页面刷新页面保持页面所在位置

实现功能:在工作经历情况下,点击保存,form表单提交后需要保持在原始位置,并重新加载数据;

<script src="https://cdn.staticfile.org/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>

<script>

    $(window).unload(function (){
        const top=$(window).scrollTop();

        $.cookie("scroll_top",top);
    });

    $(document).ready(function () {
        const top=$.cookie("scroll_top");

        $('html,body').animate({
            scrollTop: top
        },100);
    })
</script>

https://www.runoob.com/jquery/jquery-cookie-plugin.html

 

 

 


版权声明:本文为qq_36394496原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。