如何将数据从表单获取到javascript并重定向到另一个页面?

如何将数据从表单获取到javascript并重定向到另一个页面?,javascript,html,forms,local-storage,Javascript,Html,Forms,Local Storage,我有一个html5表格,上面有名字、姓氏等。我使用表单的原因是用户必须填写所有内容,因为我使用的是必需的。我想将所有数据保存在localStorage中,为此我需要将数据移动到JavaScript中 当用户重定向到另一个页面时,按下submit按钮时,如何访问JavaScript中的数据 代码如下: Html5 试试这个 Java脚本 function storeDetails() { if(typeof(Storage)!=="undefined") { localSt

我有一个html5表格,上面有名字、姓氏等。我使用表单的原因是用户必须填写所有内容,因为我使用的是
必需的
。我想将所有数据保存在localStorage中,为此我需要将数据移动到JavaScript中

当用户重定向到另一个页面时,按下
submit
按钮时,如何访问JavaScript中的数据

代码如下:

Html5


试试这个

Java脚本

function storeDetails() {
    if(typeof(Storage)!=="undefined") {
       localStorage.setItem('name', document.getElementById('Name').value));                              
       //code to store other values will go here
    } else {
        alert('Your browser do not support local storage');
    }
}
HTML

<form id="TheForm" method="post" onsubmit="javascript:storeDetails();" action=" ">
   <input type="text" id="Name" placeholder="*Förnamn" required >
   <input type="text" id="Surname" placeholder="*Efternamn" required >
   <input type="email" id="FirstEmail" placeholder="*e-postadress" autocomplete="on" required >
   <input type="email" id="SecondEmail" placeholder="*Verifiera e-postadress" autocomplete="off" required >
   <input type="text" id="Address" placeholder="*Adress" required >
   <input type="submit" id="Submit" onclick="function()" value="Skicka">
</form> 

试试这个

Java脚本

function storeDetails() {
    if(typeof(Storage)!=="undefined") {
       localStorage.setItem('name', document.getElementById('Name').value));                              
       //code to store other values will go here
    } else {
        alert('Your browser do not support local storage');
    }
}
HTML

<form id="TheForm" method="post" onsubmit="javascript:storeDetails();" action=" ">
   <input type="text" id="Name" placeholder="*Förnamn" required >
   <input type="text" id="Surname" placeholder="*Efternamn" required >
   <input type="email" id="FirstEmail" placeholder="*e-postadress" autocomplete="on" required >
   <input type="email" id="SecondEmail" placeholder="*Verifiera e-postadress" autocomplete="off" required >
   <input type="text" id="Address" placeholder="*Adress" required >
   <input type="submit" id="Submit" onclick="function()" value="Skicka">
</form> 



jQuery是一个选项吗?如果是这样的话,序列化表单数据,然后存储它。我想这行得通。。还有其他的方法吗?事实上,不,它不适用于Vanilla JS,您可以直接访问DOM元素。例如,
var name=document.getElementById(“name”).value
将把Name的值存储在一个名为“Name”的JS变量中。只有当所有字段都已填充时才会调用它吗?我是否应该将按钮和表单标签中的下一页的函数放在onclick=“”?jQuery是一个选项吗?如果是这样的话,序列化表单数据,然后存储它。我想这行得通。。还有其他的方法吗?事实上,不,它不适用于Vanilla JS,您可以直接访问DOM元素。例如,
var name=document.getElementById(“name”).value
将把Name的值存储在一个名为“Name”的JS变量中。只有当所有字段都已填充时才会调用它吗?我是否应该将按钮的函数放在onclick=“”,下一页在表单标签中运行?我是否应该给出函数名称?哈哈,我猜不是:D我是指var submit=funcon()和windows.onload=function(),控制台给出错误:无法读取null的属性“attachEvent”。它显示form.attachEvent行你的表单的ID是什么?我应该给出函数名吗?哈哈,我猜不是:D我指的是变量submit=functon()和windows.onload=function(),控制台给出了一个错误:无法读取null的属性“attachEvent”。它显示表单。附件事件行您的表单的ID是什么?