我有一个表单,用户必须填写所有字段。填写完所有字段并按下提交按钮后,我希望将数据存储在本地存储中,然后将用户重定向到另一个页面,但由于某种原因,此代码无法正常工作,任何线索为什么?
的 HTML5 的
<form id="TheForm" action="SlutSidan.html" method="post">
<div id="Row">
<input type="text" id="Name" placeholder="*Förnamn" required >
<input type="text" id="Surname" placeholder="*Efternamn" required >
</div>
<div id="Row">
<input type="email" id="FirstEmail" placeholder="*e-postadress" autocomplete="on" required >
<input type="email" id="SecondEmail" placeholder="*Verifiera e-postadress" autocomplete="off" required >
</div>
<div id="Row">
<input type="text" id="Town" placeholder="*Ort" required >
</div>
<div id="Row">
<input type="text" id="Address" placeholder="*Adress" required >
</div>
<div id="Row">
<input type="text" id="PostCode" placeholder="*Postnummer" required >
</div>
<div id="Row">
<input type="text" id="MobileNumber" placeholder="*Mobilnummer" required >
<input type="text" id="TelephoneNumber" placeholder="Telefonnummer" >
</div>
<textarea id="Comment" placeholder="Förslag på hur vi skulle kunna förbättra oss!"></textarea>
<input type="submit" id="Submit" value="Skicka">
</form>
的的Javascript 的
var submit = function () {
var name = document.getElementById('Name').value;
var surname = document.getElementById('Surname').value;
var firstemail = document.getElementById('FirstEmail').value;
var getOrderNumber = localStorage.getItem('OrderNumberTemp');
localStorage.setItem(getOrderNumber + ' Namn', name);
localStorage.setItem(getOrderNumber + ' Efternamn', surname);
localStorage.setItem(getOrderNumber + ' Email', firstemail);
// Save all the other fields
};
window.onload = function () {
var form = document.getElementById('TheForm');
if (form.attachEvent) {
form.attachEvent('Submit', submit);
} else {
form.addEventListener('Submit', submit);
}
}
PS。用户确实被重定向但没有保存