密码校验

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.red{
border: 1px solid red;
}
</style>
<script src="../angular-1.5.5/angular.js"></script>
<script>
var myapp=angular.module("myapp",[]);
myapp.controller("myCtrl",function($scope){
$scope.check=false;
$scope.pas1="";
$scope.pas2="";
$scope.show=false;
$scope.opt="只有输入框样式变化";

$scope.fun=function(){
console.log($scope.opt);
if($scope.opt=="只有输入框样式变化"){
$scope.$watch("pas2",function(value){
if(value!=""){
if(value==$scope.pas1){
$scope.check=false;
}else{
$scope.check=true;
}
}
});
}else if($scope.opt=="显示错误提示"){
$scope.$watch("pas2",function(value){
if(value!=""){
if(value==$scope.pas1){
$scope.check=false;
$scope.show=false;
}else{
$scope.check=true;
$scope.show=true;
}
}
});
}else if($scope.opt=="点击提交"){
$scope.tj=function(){
if($scope.pas2!=""){
if($scope.pas2==$scope.pas1){
$scope.check=false;
$scope.show=false;
}else{
$scope.check=true;
$scope.show=true;
}
}
}
}
}
})
</script>

</head>
<body ng-app="myapp" ng-controller="myCtrl">
<input type="password" ng-model="pas1" ng-class="{red:check}"><br>
<input type="password" ng-model="pas2" ng-class="{red:check}"><br/>
<ul ng-show="show">
<li>密码长度不小于6</li>
<li>密码不能为空</li>
<li>两次密码输入不一致</li>
</ul>
<button ng-click="tj()">按钮</button><br/>
<select ng-model="opt" ng-change="fun()">
<option>只有输入框样式变化</option>
<option>显示错误提示</option>
<option>提交</option>
</select>
</body>
</html>
posted @ 2017-10-24 10:29  小马哥(马云)  阅读(305)  评论(0编辑  收藏  举报