关闭并重新打开后继续HTML表单填写 [英] Continue HTML form filling after closing and re-opening again

查看:189
本文介绍了关闭并重新打开后继续HTML表单填写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以临时保存HTML表单中的填充数据?我的意思是,如果我有这样的形式:

There is any way to temporary save filled data in HTML form? I mean If I have form like this:

Name    [ John  ]
Email   [       ]
Address [       ]

关闭窗口并重新输入www.domain.com/form.php John 值仍然会输入到名称文本框中?

That after closing window and re-entering again to www.domain.com/form.php John value still be entered in Name text-box?

我应该为它使用 SESSIONS 吗?或者我应该将每个输入的字段自动插入数据库?您有任何想法吗?

Should I use SESSIONS for It? Or should I insert every entered field to database automatically? Have you any ideas?

更新

/ Microsoft Edge,但未成功,刷新浏览器后填充字段不保存。也许有什么不对?

I've tried following with Chrome / Microsoft Edge, but unsuccessfully, filled fields not saving after refreshing browser. Maybe something did wrong?

  <script>
// Check browser support
if (typeof(Storage) !== "undefined") {
    // Store
    localStorage.setItem("FirstName", "Hitesh");
    // Retrieve
    document.getElementById("FirstName").value = localStorage.getItem("FirstName");
} else {
    document.getElementById("FirstName").value = "Sorry, your browser does not support Web Storage...";
}
  </script>

<input id="FirstName" type="text" name="FirstName" class="field-style" placeholder="First Name" required /> 


推荐答案

以下是使用自动填充的表单示例,您可以使用local storage

here is example of form with autofill you can use localstorage

 <input id="FirstName" type="text" name="FirstName" class="field-style" placeholder="First Name" required onchange="save()"/> 

 <script>
// Check browser support
if (typeof(Storage) !== "undefined") {
    if(localStorage.getItem("FirstName")!=""){

    }else{
    // Store
        localStorage.setItem("FirstName", "Hitesh");
    }
    // Retrieve
    document.getElementById("FirstName").value = localStorage.getItem("FirstName");
} else {
    document.getElementById("FirstName").value = "Sorry, your browser does not support Web Storage...";
}
 function save(){
    var name = document.getElementById('FirstName').value;
  localStorage.setItem("FirstName", name);
 }    
  </script>

这篇关于关闭并重新打开后继续HTML表单填写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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