目前正在处理本地存储,在第一页中,如果用户选择第二页面板中的第一个单选按钮,则必须隐藏两个单选按钮。如果用户选择单选按钮,则第二页验证中的一个文本字段不应发生。我不知道如何使用 localStorage 或 ajax 哪一个是最好的。
当我看到SO时我得到了一些东西window.localStorage.setItem("key_name", "stringValue");
我该如何使用这个?
第一页代码
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<meta charset="utf-8">
<title>First page</title>
</head>
<body>
<form id="first_pge" class="first_pge" action="second.page">
<input type="radio" name="radio" id="first_radio"/>
<input type="radio" name="radio" id="second_radio"/>
<input type="button" value="submit" id="btn_sub"/>
</form
</body>
</html>
第二页
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/additional-methods.min.js"></script>
<script>
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$("#myform").validate({
rules: {
field: {
required: true
}
}
});
</script>
<meta charset="utf-8">
<title>JS Bin</title>
<style>
.div_panel {
background-color: yellow;
font-size: 16px;
}
</style>
</head>
<body>
<form id="myform" class="myform">
<div class="div_panel">First</div>
<div> </div>
<input type="text" id="field" class="field" />
<input type="button" required value="Submit" id="btn_sub1" />
</form>
</body>
</html>
目前按照以下用户使用 jQuery 帮助了我。
在第一页我是这样设置的
storeData();
function storeData()
{
alert("check");
localStorage.setItem('pg', $('#basicForm #pg').attr('checked', 'checked'));
//alert("yes" + getd);
localStorage.setItem('cu', $('#basicForm #cu').attr('checked', 'checked'));
}
当我默认在第二页中设置此选项时,如果用户直接打开第二页,则特定的 div 会隐藏。
if( localStorage.getItem('pg') )
{
$('#edu_info').hide();
}