js实现页面刷新滚动条位置不变

今天因为这个问题困扰了很久网上的例子都尝试没效果,后来发现一点原来是内容最外层没有div的原因

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SpotChkDetail.aspx.cs" Inherits="Topevery.DUM.Web.Observer.SpotChkDetail" %> <script runat="server"> protected override bool HeaderScriptFilter(Topevery.Framework.Web.Configuration.Script val) { switch (val.Key) { case "ajaxpro2.prototype": case "ajaxpro2.core": case "ajaxpro2.converter": case "ajaxpro2.onloading": case "ajaxpro2.assembly.AjaxFunction": case "my97": case "image": case "jquery.pagination": case "jquery.jqGrid.locale": case "jquery.jqGrid": case "jquery-load-image": case "jquery.validationEngine": case "jquery.validationEngine-zh": case "WeiBo": case "jquery.mousewheel": case "jquery.iviewer": case "jquery.gallery.singer": return true; default: return base.HeaderScriptFilter(val); } } protected override bool HeaderStyleFilter(Topevery.Framework.Web.Configuration.Style val) { switch (val.Key) { case "jqgrid": case "jqgrid-grey": case "validationEngine": return true; default: return base.HeaderStyleFilter(val); } } </script> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <form runat="server"> <div> <div> <div> <span></span><strong>抽查</strong> </div> <div> <object classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> </object> <input type="button" value="打 印" /> <input type="button" value="打印预览" /> </div> <div> <span>抽查时间:<asp:Label runat="server" Text="Label"></asp:Label>&nbsp;&nbsp; 失效时间:<asp:Label runat="server" Text="Label"></asp:Label>&nbsp;&nbsp; 消息内容:<asp:Label runat="server" Text="Label"></asp:Label></span> <div> <asp:Button runat="server" Text="刷新" /> </div> </div> </div> <div> <div> <asp:Repeater runat="server" OnItemDataBound="Repeater1_ItemDataBound"> <%--OnItemCommand="Repeater1_ItemCommand"--%> <HeaderTemplate> <table> <tr> <th>巡查员头像 </th> <th>姓 名 </th> <th>是否超时 </th> <%--<th>城管通号码 </th> <th>城管通版本 </th>--%> <th>消息状态 </th> <th>审核状态 </th> <th>审核 </th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td rowspan="2" valign="middle"> <img runat="server" /> </td> <td> <%# Eval("c_name")%>&nbsp; <asp:HiddenField runat="server" Value='<%# Eval("c_ob_id") %>' /> <asp:HiddenField runat="server" Value='<%# Eval("c_id") %>' /> </td> <td> <%# Eval("c_is_over_time")%>&nbsp; </td> <%--<td> <%# Eval("c_pda_number")%>&nbsp; </td> <td> <%# Eval("c_pda_version")%>&nbsp; </td>--%> <td> <%# Eval("notify_state")%>&nbsp; </td> <td> <%# Eval("eligible_state")%>&nbsp; </td> <td> <divc_is_eligible").ToString() !="0"?"none":"" %>"> <%--<asp:LinkButton runat="server" CommandName="lnk_poto" CommandArgument='<%# Eval("c_id") %>'>重摄</asp:LinkButton> <asp:LinkButton runat="server" CommandName="lnk_ok" CommandArgument='<%# Eval("c_id") %>'>合格</asp:LinkButton> <asp:LinkButton runat="server" CommandName="lnk_no" CommandArgument='<%# Eval("c_id") %>'>不合格</asp:LinkButton>--%> <a href='#'><span></span>重摄</a> <a href='#'><span></span>合格</a> <a href='#'><span></span>不合格</a> </div> </td> </tr> <tr> <td colspan="5"> <table> <tr> <asp:Repeater runat="server"> <ItemTemplate> <td> <div> <div+'<%#Eval("FileId") %>'> <div> <a title='点击放大' href="javascript:void(0)" sourceSrc='<%#Eval("Imageurl") %>' largeSrc='<%#Eval("Imageurl") %>'><img src='<%#Eval("Imagethumbil") %>' /><span><%#Eval("Summary") %></span></a> </div> </div> </div> </td> </ItemTemplate> </asp:Repeater> </tr> </table> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <input type="hidden" runat="server" value="0" /><!----存放scorllTop值--> </div> </div> </div> <script type="text/javascript"> $(document).ready(function () { TUILayout("form"); //LoadImage(); $(".div_img").gallery({ gallerySize: { width: 90, height: 120 }, fullView: "true" //ture为允许点击图像全屏浏览 }); }); function LoadImage() { var jq_o_list = $("#observers div[@ref_id]"); for (var i = 0 ; i < jq_o_list.length; i++) { load_to(jq_o_list[i]); } } function load_to(obj) { var jq_o = $(obj); Topevery.DUM.Web.AjaxFunction.GetEvtDefault(jq_o.attr("ref_id"), function (ajaxResult) { var val = ajaxResult.value; jq_o.empty(); jq_o.append(val.Html); }); } //$("#div_evt_img").gallery({ // images: evt_img_list, // thumbSize: { width: 65, height: 60 },//缩略图大小 // gallerySize: { width: 380, height: 280 },//画廊图(中间大图)大小 // thumbDisplayNum: 4,//缩略图显示数量 // scalingSize: { width: 360, height: 260 },//画廊图(中间大图)自动比例缩放最大大小 // fullView: "true" //ture为允许点击图像全屏浏览 //}); function Reminder() { NotSelectEvt("已经再次发送消息通知巡查员!"); } function review(id, type, content) { if (confirmL("确认" + content + "吗?", function () { Topevery.DUM.Web.AjaxFunction.ReviewImg(id, type); $("#btnRef").click(); })) { } } </script> </form> </body> </html> <script type="text/javascript"> window.onbeforeunload = function () { var scrollPos; if (typeof window.pageYOffset != 'undefined') { scrollPos = window.pageYOffset; } else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') { scrollPos = document.documentElement.scrollTop; } else if (typeof document.body != 'undefined') { scrollPos = document.body.scrollTop; } document.cookie = "scrollTop=" + scrollPos; //存储滚动条位置到cookies中 } window.onload = function () { if (document.cookie.match(/scrollTop=([^;]+)(;|$)/) != null) { var arr = document.cookie.match(/scrollTop=([^;]+)(;|$)/); //cookies中不为空,则读取滚动条位置 document.documentElement.scrollTop = parseInt(arr[1]); document.body.scrollTop = parseInt(arr[1]); } } </script>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzzyds.html