1、js代码
$scope.login={};
$scope.login.chk = true;$scope.addCookie = function (name,value,days,path)
{
var name = escape(name);
var value = escape(value);
var expires = new Date();
expires.setTime(expires.getTime() + days * 3600000 * 24);
path = path == "" ? "" : ";path=" + path;
var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString();
document.cookie = name + "=" + value + _expires + path;
}
$scope.getCookieValue = function (name)
{
var name = escape(name);
var allcookies = document.cookie;
name += "=";
var pos = allcookies.indexOf(name);
if (pos != -1){
var start = pos + name.length;
var end = allcookies.indexOf(";",start);
if (end == -1) end = allcookies.length;
var value = allcookies.substring(start,end);
return (value);
}else{
return "";
}
} ;
$scope.deleteCookie =function(name,path)
{
var name = escape(name);
var expires = new Date(0);
path = path == "" ? "" : ";path=" + path;
document.cookie = name + "="+ ";expires=" + expires.toUTCString() + path;
};
$scope.loginOnload = function()
{
var userNameValue = $scope.getCookieValue("userName");
$scope.login.user_name = userNameValue;
var userPassValue = $scope.getCookieValue("userPass");
$scope.login.user_pwd = userPassValue;
var userRemPwd=$scope.getCookieValue("rem_pwd");
$scope.login.chk = (userRemPwd=="true");
// var $chk=$("input[name=chk]");
// $chk.attr("checked",false);
};
$scope.clearPwdClick = function()
{
$scope.deleteCookie("userPass");
$scope.login.user_pwd = "";
};
$scope.backTestConfigSaveClick = function(user_name, user_pwd,rem_pwd) {
//$('#loginModal').modal('hide');
var userName = $scope.login.user_name;
var rem_pwd =$scope.login.chk;
if(userName == '')
{
alert("请输入用户名。")
return;
}
var userPass = $scope.login.user_pwd;
if(userPass == '')
{
alert("请输入密码。")
return;
}
if(rem_pwd)
{
//添加cookie
$scope.addCookie("userName",userName,7,"/");
$scope.addCookie("userPass",userPass,7,"/");
$scope.addCookie("rem_pwd",rem_pwd,7,"/");
}
else
{
$scope.deleteCookie("userPass");
$scope.login.user_pwd ="";
$scope.addCookie("rem_pwd",rem_pwd,7,"/");
}
};
2、html代码
<div class="modal-dialog-lg" data-ng-init="loginOnload()">
<div class="modal-content">
<div class="modal-header">
<!-- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button> -->
<h4 class="modal-title">User Login</h4>
</div>
<table bordercolor="red" class="input-group">
<tr>
<td align = "left" background="img/acsy2.jpg" width="1000" style="border-right-style:none">
<img src="img/acsy1.jpg" width="1500" height="130" />
</td>
<td align="middle" background="img/acsy2.jpg" width="420" hight="150" style="border-left-style:none">
<label for="username">Username:</label>
<input type="text" class="form-control" ng-model="login.user_name"/>
<br>
<label for="password">Password:</label>
<input type="password" class="form-control" ng-model="login.user_pwd" />
<br>
<label for="rmbpassword">Remember Password</label>
<input type="checkbox" name="chk" ng-model="login.chk"/>
<button align="left" class="btn btn-xs " ng-click="clearPwdClick()">Clear Password</button>
<br></td>
</tr>
</table>
<div class="modal-footer">
<button type="button" class="btn btn-primary" ng-click="backTestConfigSaveClick(login.user_name,login.user_pwd,login.chk)">Login</button>
</div>
</div>
</div>