记住来自不同页面的表单域的值 [英] Remember values from form field for a different page

查看:85
本文介绍了记住来自不同页面的表单域的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有第1页和第2页。



在Page 1上,如果我点击转到第2页按钮,我将转到第2页,也在第1页输入字段此字段在此处作为占位符。



在第2页我有一个按钮回到第1页,当我点击它时,它会将我带到第1页。



我想要的是,在点击返回第1页后,在点击转到第2页之前,自动完成输入此字段在此处 。



波纹管您有我当前的代码:

第1页 p>

 < script type =text / javascript> 
function getRandomPage(){
document.getElementById('MyButton')。onclick = location.href =/?random = 1;
};
< / script>

< form>
< div class =checkboxesalign =center>
< input type =hiddenname =randomvalue =1>< br>
< input placeholder =这个字段在这里style =width:296px; height:30px; type =textautocomplete =off>< br>
< label for =x>< input type =checkboxid =xchecked =>< span>一些文字< / span>< / label>< br>
< label for =y>< input type =checkboxid =ydisabled =>< span>一些文字< / span>< / label>< br>
< button id =MyButtontype =submit>前往第2页< / button>
< / div>
< / form>

Page 2

 < form action =/> 
< div align =center>
< button type =submit>返回到第1页< / button>
< / div>
< / form>

我想也许可以用js来完成?但我不知道如何解决方案

您可以使用本地存储,如下所示:

  //存储
localStorage.setItem(lastname,Smith);
//检索
document.getElementById(result)。innerHTML = localStorage.getItem(lastname);


I have "Page 1" and "Page 2".

On "Page 1" if I click on the button "Go To Page 2" I will get to "Page 2", also on "Page 1" I have a input field "This field right here" as placeholder.

On "Page 2" I have a button "Go Back To Page 1" that when I click it, it will bring me to "Page 1".

What I want is, after I click "Go Back To Page 1" to autocomplete the input "This field right here" with the submited value before I click on "Go To Page 2".

Bellow you have my current code:

Page 1

<script type="text/javascript">
    function getRandomPage () {
    document.getElementById('MyButton').onclick = location.href = "/?random=1";      
        };
</script>

<form>
<div class="checkboxes" align="center">
        <input type="hidden" name="random" value="1"><br>
        <input placeholder="This field right here" style="width: 296px; height: 30px;" type="text" autocomplete="off"><br>
        <label for="x"><input type="checkbox" id="x" checked=""><span> Some Text </span></label><br>
        <label for="y"><input type="checkbox" id="y" disabled=""><span> Some Text </span></label><br>
        <button id="MyButton" type="submit">Go To Page 2</button>
    </div>
</form>

Page 2

<form action="/">
    <div align="center">
        <button type="submit">Go Back To Page 1</button>
    </div>
</form>

I'm thinking maybe it could be done with js maybe? But I don't know how

解决方案

You can use local storage from HTML5, like below:

// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname"); 

这篇关于记住来自不同页面的表单域的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆