有两个html页面.当我从下一页恢复到第一页时,我希望保存第一页的数据状态
there are two html pages. I want the data status of first pages to saved when I reverting from next page to first page
当我单击下一页的后退按钮时,复选框值不应重置。
它应该和我检查或未检查的一样。下面是第一页和下一页的代码。
第一页
<!DOCTYPE html>
<html>
<body>
<form>
<input type="checkbox" name="code" value="ECE">ECE<br>
<input type="checkbox" name="code" value="CSE">CSE<br>
<input type="checkbox" name="code" value="ISE">ISE<br>
<br>
<input type="button" onclick="dropFunction()" value="save">
<br><br>
<script>
function dropFunction() {
var branch = document.getElementsByName("code");
var out = "";
for (var i = 0; i < branch.length; i++) {
if (branch[i].checked == true) {
out = out + branch[i].value + " ";
window.location.href="next.html";
}
}
}
</script>
</form>
</body>
</html>
下一页
<html>
<head>
<title>Welcome to </title>
</head>
<body color="yellow" text="blue">
<h1>welcome to page</h1>
<h2>here we go </h2>
<p> hello everybody<br></p>
</body>
<image src="D:'images.jpg" width="300" height="200"><br>
<button onclick="goBack()">Go Back</button>
<script>
function goBack() {
window.location.href="first.html";
}
</script>
</body>
</html>
完整解决方案:示例。首先将id添加到您的复选框中:
<input type="checkbox" name="code" value="ECE" id='1'>ECE<br>
<input type="checkbox" name="code" value="CSE" id='2'>CSE<br>
<input type="checkbox" name="code" value="ISE" id='3'>ISE<br>
<input id="spy" style="visibility:hidden"/>
然后更改您的dropFunction:
function dropFunction() {
var branch = document.getElementsByName("code");
var out = "";
localStorage.clear();
for (var i = 0; i < branch.length; i++)
if (branch[i].checked == true)
localStorage.setItem(branch[i].id, true);
for (var i = 0; i < branch.length; i++) {
if (branch[i].checked == true) {
out = out + branch[i].value + " ";
window.location.href="next.html";
}
}
}
并在first.html中添加一些新的javascript代码:
window.onload = function() {
var spy = document.getElementById("spy");
if(spy.value=='visited')
for(var i=1;i<=3;i++)
if(localStorage.getItem(i))
document.getElementById(i).checked=true;
spy.value = 'visited';
}
相关文章:
- 如何为AngularJS制作智能表中第一页和最后一页的跳过按钮
- 在第一页加载时隐藏字段,而不是在php发布之后
- JS文件未加载第一页加载
- 如何在第一页加载时使jQuery弹出消息
- 如何自动从一个页面移动到另一个页面,然后回到 html 表格中分页的第一页
- jquery手机应用程序的第一页必须是index.html
- ngTable筛选器仅适用于第一页
- Javascript(Adobe Acrobat XI)从表单第一页的输入答案填充第二页表单
- 第一页加载时,有角度的ng网格固定标题不是静态的
- 自定义JQUERY未在分页页面上加载(第一页除外)
- 链接在第一页加载时瞬间变蓝
- 使用turn.js I'I’我正试图在加载时把角落的第一页翻进去
- 区分剑道网格上一页/下一页点击与转到第一页/最后一页点击事件
- 使用javascript从另一页(第三页)刷新一页(第一页)
- setAutoGrow()只适用于应用程序的第一页,这有什么错
- 复选框只适用于第一页-数据表、轨道
- jQuery 移动页面显示事件未在第一页上触发
- 为什么 Java 脚本单击事件在第一页加载时没有触发
- 我的jquery代码正在运行第一页,但没有运行第二页
- 有两个html页面.当我从下一页恢复到第一页时,我希望保存第一页的数据状态