js 刷新页面后保持页面原来的位置

使用js方法:

1.window.scrollTo(x, y);  页面左滚动x,向下滚动y;

2.document.documentElement.scrollTop : 或缺页面滚动的高度。

eg:

js:

    <script src="../../Js/jquery/jquery-1.5.2.min.js" type="text/javascript"></script> 
    <script type="text/javascript">
        $(function () { 
            window.scrollTo(0, $("#hdnvalue").val());

            $("#rdoBusinessDriver,#rdoDangerPrac,#ddlPracTypeSmallCatelog").click(function () {
                $("#hdnvalue").val(document.documentElement.scrollTop); 
            });
        });
    </script>

html:

<asp:RadioButton ID="rdoBusinessDriver" runat="server" GroupName="1" Text="驾驶员" Checked="true"/>
<asp:RadioButton ID="rdoDangerPrac" runat="server" GroupName="1" Text="从业人员"/>
<asp:DropDownList ID="ddlPracTypeSmallCatelog" runat="server" Width="190px" ></asp:DropDownList>

<input type="hidden" id="hdnvalue" runat="server" value="0" />//存放scorllTop值


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要保证刷新页面后依旧保持最新的页面,有以下几种方法: 1. 在后端控制浏览器缓存。可以在HTTP响应头中设置缓存控制策略,如设置`Cache-Control`为`no-cache`,或设置`Expires`为一个过去的时间,这样可以告诉浏览器不要缓存页面。在Spring Boot中,可以使用`WebMvcConfigurer`来配置缓存控制策略,如下所示: ```java @Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**") .addResourceLocations("classpath:/static/") .setCacheControl(CacheControl.noCache()); } } ``` 2. 在前端控制缓存。可以在HTML页面中使用meta标签来设置缓存策略,如下所示: ```html <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Expires" content="0"> ``` 这样可以告诉浏览器不要缓存当前页面。 3. 使用版本号或时间戳来更新静态资源。在HTML页面中引用静态资源时,可以在URL中添加版本号或时间戳,如下所示: ```html <link rel="stylesheet" href="css/style.css?v=1.0"> <script src="js/script.js?t=20220606"></script> ``` 每次更新静态资源时,修改版本号或时间戳即可。这样可以保证浏览器能够获取到最新的静态资源,从而保证页面的最新状态。 以上是几种比较常见的保证刷新页面后依旧保持最新的页面的方法,可以根据具体情况选择适合自己的方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值