Angular表单判断不同显示效果

来源:互联网 发布:python怎么保存文件 编辑:程序博客网 时间:2024/06/05 19:43
<!DOCTYPE html>
<html>


<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/angular.min.js"></script>
<style>
.ip {
border: 1px solid red;
}
</style>
</head>


<body ng-app="MyApp" ng-controller="MyCont">
<select ng-change="sel()" ng-model="xuan">
<option>只有输入框样式变化</option>
<option>显示详细信息</option>
<option>点击时显示效果</option>
</select><br /> 输入密码
<input type="text" ng-model="pwd" class="{{pass}}" /><br /> 重复密码
<input type="text" ng-model="pwd1" class="{{pass}}" /><br />
<button ng-click="cli()">提交</button>
<ul class="ul" ng-hide="hi">
<li ng-repeat="li in xin">{{li}}</li>
</ul>
<script type="text/javascript">
var mo = angular.module("MyApp", []);
mo.controller("MyCont", function($scope) {


$scope.sel = function() {
var aa = $scope.xuan;
$scope.xin = [];
if(aa == "只有输入框样式变化") {
var pwd = $scope.pwd;
var pwd1 = $scope.pwd1;
if(pwd == undefined || pwd1 == undefined) {
$scope.pass = "ip";
}
if(pwd.length <= 6 || pwd1.length <= 6) {
$scope.pass = "ip";
}
if(pwd != pwd1) {
$scope.pass = "ip";
}
} else if(aa == "显示详细信息") {
var pwd = $scope.pwd;
var pwd1 = $scope.pwd1;
$scope.pass = "vp";
if(pwd == undefined || pwd1 == undefined) {
$scope.xin.push("密码不能为空");
}


if(pwd.length <= 6 || pwd1.length <= 6) {
$scope.xin.push("密码长度不能小于六位")
}
if(pwd != pwd1) {
$scope.xin.push("输入两次密码不同")
}


} else if(aa == "点击时显示效果") {
$scope.hi = true;
$scope.pass = "vp";
}
}
$scope.cli = function() {
var pwd = $scope.pwd;
var pwd1 = $scope.pwd1;
$scope.xin = [];
if(pwd == undefined || pwd1 == undefined) {
$scope.xin.push("密码不能为空");
}
if(pwd.length <= 6 || pwd1.length <= 6) {
$scope.xin.push("密码长度不能小于六位")
}
if(pwd != pwd1) {
$scope.xin.push("输入两次密码不同")
}
$scope.hi = false;
}
})
</script>
</body>


</html>