[英]Jquery radio button checked value on page refresh
I have the following two radio buttons. 我有以下两个单选按钮。 Switching between the two values works. 在两个值之间切换是可行的。 But after a page refresh the selected value is not there anymore. 但是在刷新页面后,所选值不再存在。 How can I handle this problem. 我该如何处理这个问题。 Is there a jquery library which can handle this? 是否有可以处理此问题的jquery库? Any solutions which works on each browser? 任何适用于每种浏览器的解决方案? Thanks for suggestions. 感谢您的建议。
<input type="radio" name="lr" id="open" class="required" value="open to all" checked="checked" />
<input type="radio" name="lr" id="login_area" class="required myOption" value="login_area" />
<label for="login_area">Register</label>
<div class="login_area">...</div>
<div class="signUp_area">...</div>
$(document).ready(function() {
$('.myOption').click(function() {
var $stat = null;
$stat = $('#login_area')[0].checked;
if ($stat === true) {
$('.signUp_area').show();
$('.login_area').hide();
} else {
$('.login_area').show();
$('.signUp_area').hide();
}
});
});
JavaScript is stateless. JavaScript是无状态的。 You have to either use localStorage, cookies, or a server session to persist after a page refresh. 您必须使用localStorage,Cookie或服务器会话才能在页面刷新后继续存在。 Client side code does not do this unless stored in memory or a database. 除非存储在内存或数据库中,否则客户端代码不会执行此操作。
Should you use jquery cookie. 你应该使用jQuery cookie。
To set: 设置:
$.cookie("var", "10");
To get: 要得到:
$.cookie("var");
To delete: 删除:
$.cookie("var", null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.