在用jquery mobile,想知道怎么用localstorage 保存checkbox的状态
1 回答

慕尼黑8549860
TA贡献1818条经验 获得超11个赞
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <script src="jquery.min.js"> </script> </head> <body> <input type="checkbox" name="" id="cb" /> <script> $("#cb").change(function(){ var b = $(this).is(":checked"); localStorage.setItem('checkbox', b); }); $(function(){ if(localStorage.checkbox == "true"){ $("#cb").prop("checked", "checked"); } }); </script> </body> </html>
添加回答
举报
0/150
提交
取消