Jquery 登陆页面 Cookie记住用户名密码 (可设定保存时间)
2.还需要一个jquery-1.6.1.min.js ,这个大家应该都有 ,就不传了。
3.页面
- //登录事件
- ? ?? ???function doLogin() {
- ? ?? ?? ?? ?? ? var userName = document.getElementById("username");
- ? ?? ?? ?? ?? ? var pwd = document.getElementById("password");
- ? ?? ?? ?? ?? ? if(userName.value.replace(/ /g,"")==""){
- ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???alert("用户名不能为空!");
- ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???userName.focus();
- ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???return false;
- ? ?? ?? ?? ?? ?? ?? ?? ?}
- ? ?? ?? ?? ?? ? if(pwd.value==""){
- ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???alert("密码不能为空!");
- ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???pwd.focus();
- ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???return false;
- ? ?? ?? ?? ?? ?? ?? ?? ?}
- ? ?? ?? ?? ?? ? setCookie('cookUser', userName.value, time, '/');//set 获取用户名和密码 传给cookie
- ? ?? ?? ?? ?? ? setCookie('cookPass', pwd.value, time, '/');
- ? ?? ?? ?? ?? ? document.login_form.submit();
- ? ?? ?? ?? ?? ?? ?? ?? ?
- ? ?? ?? ?? ?? ? }
- ? ?? ?? ?? ?? ? //设置Cookie保存时间
- ? ?? ?? ?? ?? ? var time = 0;
- ? ?? ?? ?? ?? ??
- ? ?? ?? ?? ?? ? $(document).ready(function(){
- ? ?? ?? ?? ?? ? //获取Cookie保存的用户名和密码
- ? ?? ?? ?? ?? ? var username = getCookieValue("cookUser");
- ? ?? ?? ?? ?? ? var password = getCookieValue("cookPass");
- ? ?? ?? ?? ?? ??
- ? ?? ?? ?? ?? ? if (username !='' && password !='' ) {
- ? ?? ?? ?? ?? ?? ?? ?? ?$("#username").val(username);
- ? ?? ?? ?? ?? ?? ?? ?? ?$("#password").val(password);
- ? ?? ?? ?? ?? ?? ?? ?? ?$("#rememberPW").attr("checked", true);
- ? ?? ?? ?? ?? ? }else?
- ? ?? ?? ?? ?? ?? ?? ?? ?$("#rememberPW").attr("checked", false);
- ? ?? ?? ?? ?? ??
- ? ?? ?? ?? ?? ? $("#rememberPW").click(function(){//记住密码
- ? ?? ?? ?? ?? ?? ?? ?? ?if($(this).attr("checked") == 'checked'){
- ? ?? ?? ?? ?? ?? ?? ?? ?time = 60 * 60 * 60;
- ? ?? ?? ?? ?? ?? ?? ?? ?}
- ? ?? ?? ?? ?? ?? ?? ?? ?});
- ? ?? ?? ?? ?? ? });
Jquery 登陆页面 Cookie记住用户名密码http://bbs.it-home.org/thread-2179-1-1.html