2 回答
TA贡献1836条经验 获得超5个赞
像这样使用submitwithaction属性form
<form name="myform" action="./html2.html" method="GET">
Event Name: <input type="text" name="name" value=""/>
Event Date and Time: <input type="datetime-local" name="date" value=""/>
Event Location: <input type="text" name="location" value=""/>
Event Notes: <input type="text" name="notes" value=""/>
<input value="submit" type="submit"/>
</form>
当你点击提交按钮时,页面同时跳转到html2.html?name=xxx&date=xxx&location=xxx...
TA贡献1797条经验 获得超6个赞
使用 localStorage 怎么样?
要存储项目,请使用localStorage.setItem("valuename", "data");.
要获得项目的价值,请使用localStorage.getItem("valuename");.
这是一个例子:
<FORM NAME="myform" ACTION="" METHOD="GET"><BR>
Event Name: <INPUT TYPE="text" NAME="name" VALUE="" id="input1"><P>
Event Date and Time: <INPUT TYPE="datetime-local" NAME="date" Value="" id="input2"><P>
Event Location: <INPUT TYPE="text" NAME="location" VALUE="" id="input3"><P>
Event Notes: <INPUT TYPE="text" NAME="notes" VALUE="" id="input4"><P>
<button onclick="myFunction()" type=submit>Submit</button>
</form>
<script>
document.getElementById('input1').value = localStorage.getItem("EventName");
document.getElementById('input2').value = localStorage.getItem("EventDateAndTime");
document.getElementById('input3').value = localStorage.getItem("EventLocation");
document.getElementById('input4').value = localStorage.getItem("EventNotes");
</script>
<script>
function myFunction() {
localStorage.setItem("EventName", document.getElementById('input1').value);
localStorage.setItem("EventDateAndTime", document.getElementById('input2').value);
localStorage.setItem("EventLocation", document.getElementById('input3').value);
localStorage.setItem("EventNotes", document.getElementById('input4').value);
}
</script>
这是一个现场演示:https ://codepen.io/marchmello/pen/eYpdmQb
添加回答
举报