duanhe3393 2016-03-29 00:22
浏览 32

将页面加载到上一个滚动点

I have a PHP page that generates a long table of items. One column lists actions available for each item (row) one of which is "delete." After deleting the record the entire page is reloaded, with the top of the table at the top of the screen. This is a bother, though. If I'm deleting an item far down in the table I want the reload to scroll to where I was, so it's easy to delete the next item. As it is, I have to manually scroll down several times and find where I was before I can delete the next row.

How can I make a new load of the page scroll automatically down to where I was?

I'm doing this in WordPress, if it makes any difference.

  • 写回答

1条回答 默认 最新

  • drus40229 2016-03-29 00:32
    关注

    The way that I did this for a previous job was to get the index of the "tr" that housed the delete button and store it into session storage. On the page reload I got the index number out of session storage and scrolled to that index.

    //function to set line index on clicking a table row        
        $("table").eq(2).on('click','tr',function () 
            {
                var lineNum = $(this).closest("tr").index();
                sessionStorage.setItem('lineNumber',lineNum);
            });
    
        //retrieves line index and scrolls to it
        var line_Number=parseFloat(sessionStorage.getItem('lineNumber'));
        $("tr").eq(line_Number)[0].scrollIntoView();    
    

    If I was doing it now, I would probably use Ajax and forget about reloading the page and simply delete the contents and leave the page where it was without having to worry about the index or scrolling to it.

    评论

报告相同问题?

悬赏问题

  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录