//$.cookie("xx");//读取xx的值 //$.cookie("xx","123");//设置xx的值为123 //$.cookie("xx","123",{expires:7})//设置xx的值为123并保存7天 有效期为7天 //$.cookie("xx","123",{expires:7,path:"/"}) <script src="js/jquery.js"></script> <script src="js/jquery.cookie.js"></script> <input type="text" placeholder="用户名" id="txtName"> <input type="password" placeholder="密码" id="txtPwd"> <input type="checkbox" id="chkRememberPwd">记住密码 <button>登录</button> <script> $(function () { $("#txtName").val($.cookie("name")); $("#txtPwd").val($.cookie("pwd")); if($.cookie("chkRememberPwd") == "1"){ $("#chkRememberPwd").prop("checked","checked"); }else{ $("#chkRememberPwd").prop("checked",""); } $("button").click(function(){ var name = $("#txtName").val(); var pwd = $("#txtPwd").val(); if($("#chkRememberPwd").is(":checked")){ console.log("2"); $.cookie("name",name); $.cookie("pwd",pwd); $.cookie("chkRememberPwd","1"); }else{ $.cookie("name",""); $.cookie("pwd",""); $.cookie("chkRememberPwd",""); } }); }) </script>