我需要使用javascript将表格数据从一个页面本地存储到表格中的另一个页面?
javascript代码
function addtext()
{
var fname = document.myform.first_name.value;
var lname = document.myform.last_name.value;
var email = document.myform.email.value;
document.writeln("Thank you! You have just entered the following:");
document.writeln("<pre>");
document.writeln("<td>First Name :</td> " + fname);
document.writeln("<td>Last Name :</td> " + lname);
document.writeln("<td>Email Address :</td> " + email);
}
HTML部分
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<form name="myform" action="confirm.php" method="get">
<td>
<label for="first_name">First Name </label>
</td>
<td>
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="last_name">Last Name </label>
</td><td><input type="text" name="last_name" maxlength="50" size="30">
</td></tr>
<tr>
<td> <label for="email">Email Address</label>
</td><td><input type="text" name="email" maxlength="80" size="30">
</td></tr><br>
<input type="submit" value="Submit" onClick="addtext()">
</form>
</tr>
</table>
答案 0 :(得分:4)
检查JSFiddle!连接。希望它可以帮到你。
var fname = document.myform.first_name.value;
var lname = document.myform.last_name.value;
var email = document.myform.email.value;
document.writeln("Thank you! You have just entered the following:");
document.writeln("<pre>");
document.writeln("<td>First Name :</td> " + fname);
document.writeln("<td>Last Name :</td> " + lname);
document.writeln("<td>Email Address :</td> " + email);
答案 1 :(得分:0)
你为什么要这样做?任何特殊原因?虽然不是最佳实践,但如果它的唯一用户偏好不是用户数据,那么通过javascript你可以通过sessionStore或localStorage来实现。
请参阅Web Storage
或者如果cookie没问题则使用jquery cookie