dongtu4559 2013-07-04 09:43
浏览 44

返回上一个包含动态内容的网页

I have developed 2 webpages: - page 1 with dynamic content - adding or removing forms by means of buttons+javascript functions + submit button for all created forms. After successful submission of data in the forms a php file redirects to page 2: - page 2 with a go-back-to-page-1 button (using window.history.go(-1) javascript function)

When going back from page 2 to page 1 the dynamically created forms seem to be lost (e.g, the original page 1 without dynamic content is viewed) which is not meant to happen.

How to keep the forms when going back to page 1? (i noticed a similar question at https://stackoverflow.com/questions/17220024/back-button-for-dynamic-textbox-generation-page-in-php-using-sesison, but without any answers).

Please your suggestions.

  • 写回答

2条回答 默认 最新

  • douchan4674 2013-07-04 10:06
    关注

    you should use only one page and process your data in ajax. Page 1 = one div and Page 2 = one another div play with attribute display (and with effect if you want)

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <div id="page1">
    page 1
    <form>
        <input type="text" id="txt1"><br>
        <button onclick="savePage1();" type="button">Page 2 ></button>
    </form>
    </div>
    <div id="page2" style="display:none;">
    page 2
    
    <button onclick="backPage1();" type="button">< Page 1</button>
    </div>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script>
    function savePage1() {
        // php processing
        /*$.ajax({
          url: "/savePage1.php",
          data: {
            data1: $('#txt1').val()
          },
          success: function( data ) {
            // ...
          }
        });*/
    
        // insert code into success
        $('#page1').hide();
        $('#page2').show();
    }
    function backPage1() {  
        $('#page2').hide();
        $('#page1').show();
    }
    </script>
    </body>
    </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况