HTML
<div class="login-input-item usertype-item" data-show="1">
<i class="icon usertype-icon"></i>
<input name="userType" value="1" type="hidden"/>
<input class="input" type="text" id="userType" placeholder="帐号" value="其它" readonly>
<i class="usertype-arrow"></i>
<div class="usertype-child-item">
<a href="javascript:;" data-id="0">管理员</a>
<a href="javascript:;" data-id="1">其它</a>
</div>
</div>
<div class="login-input-item">
<i class="icon accounts-icon"></i>
<input class="input" type="text" name="mobile" id="mobile" placeholder="帐号">
</div>
<div class="login-input-item">
<i class="icon pwd-icon"></i>
<input class="input" type="password" name="pwd" id="pwd" placeholder="密码" title="密码不能为空!">
</div>
<p class="other">
<label><input type="checkbox" name="rememberMe" οnclick="remember()"/>下次记住我</label>
<a class="forgot-pwd" href="javascript:;">忘记密码</a>
</p>
JS
//记住密码复选框的点击事件
function remember(){
var remFlag = $("input[type='checkbox']").is(':checked');
if(remFlag==true){ //如果选中设置remFlag为true
//cookie存用户名和密码,回显的是真实的用户名和密码,存在安全问题.
var conFlag = confirm("记录密码功能不宜在公共场所使用,以防密码泄露.您确定要使用此功能吗?");
if(conFlag){ //确认标志
$("#remFlag").val(true);
}else{
$("input[type='checkbox']").removeAttr('checked');
$("#remFlag").val(false);
}
}else{ //如果没选中设置remFlag为false
$("#remFlag").val(false);
}
}
//获取cookie
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
}
return "";
}
//记住密码功能
var str = getCookie("loginInfo");
if(str!=null && str!=""){
str = str.substring(0,str.length-1);
var username = str.split("#")[0];
var password = str.split("#")[1];
var role=str.split("#")[2];
showFun(role);
//自动填充用户名和密码
$("#mobile").val(username);
$("#pwd").val(password);
$("input[type='checkbox']").attr("checked", true);
}else{
showFun(1);
}
//如果密码框的值改变,就md5加密
$("#pwd").change(function () {
$("#pwd").val($.md5($("#pwd").val()));
});