前幾天沒注意作業,現在才看到,明天就要交了,有沒有哪個大佬幫忙做下作業!!?
uj5u.com熱心網友回復:
<!DOCTYPE html><html>
<head>
<meta charset="utf-8">
<!-- <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> -->
<link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.4.1/css/bootstrap.css">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://bbs.csdn.net/topics/base.js"></script>
</head>
<body ng-app="myApp" ng-controller="userCtrl">
<div class="container">
<button class="btn btn-success" ng-click="editUser('new')" data-toggle="modal" data-target="#myModal">
<span class="glyphicon glyphicon-user"></span>新增
</button>
<table class="table table-striped">
<thead>
<tr>
<th>編輯</th>
<th>名</th>
<th>姓</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td>
<button class="btn" ng-click="editUser(user.id)" data-toggle="modal" data-target="#myModal">
<span class="glyphicon glyphicon-pencil"></span>編輯
</button>
</td>
<td>{{ user.fName }}</td>
<td>{{ user.lName }}</td>
</tr>
</tbody>
</table>
<!-- 模態框(Modal) -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">名:</label>
<div class="col-sm-10">
<input type="text" ng-model="fName" ng-disabled="!edit" placeholder="名">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">姓:</label>
<div class="col-sm-10">
<input type="text" ng-model="lName" ng-disabled="!edit" placeholder="姓">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">密碼:</label>
<div class="col-sm-10">
<input type="password" ng-model="passw1" placeholder="密碼">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">重復密碼:</label>
<div class="col-sm-10">
<input type="password" ng-model="passw2" placeholder="重復密碼">
</div>
</div>
</form>
<button class="btn btn-success" ng-disabled="error || incomplete">
<span class="glyphicon glyphicon-save"></span>修改
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
</div>
</body>
</html>
uj5u.com熱心網友回復:
angular.module('myApp', []).controller('userCtrl', function($scope) {$scope.fName = '';
$scope.lName = '';
$scope.passw1 = '';
$scope.passw2 = '';
$scope.users = [
{id:1, fName:'王', lName:"二馬" },
{id:2, fName:'張', lName:"翠花" },
{id:3, fName:'麗', lName:"丫丫" },
{id:4, fName:'N', lName:"ick" },
{id:5, fName:'a', lName:"dDs" }
];
$scope.edit = true;
$scope.error = false;
$scope.incomplete = false;
$scope.editUser = function(id) {
if (id == 'new') {
$scope.edit = true;
$scope.incomplete = true;
$scope.fName = '';
$scope.lName = '';
} else {
$scope.edit = false;
$scope.fName = $scope.users[id-1].fName;
$scope.lName = $scope.users[id-1].lName;
}
};
$scope.$watch('passw1',function() {$scope.test();});
$scope.$watch('passw2',function() {$scope.test();});
$scope.$watch('fName', function() {$scope.test();});
$scope.$watch('lName', function() {$scope.test();});
$scope.test = function() {
if ($scope.passw1 !== $scope.passw2) {
$scope.error = true;
} else {
$scope.error = false;
}
$scope.incomplete = false;
if ($scope.edit && (!$scope.fName.length ||
!$scope.lName.length ||
!$scope.passw1.length || !$scope.passw2.length)) {
$scope.incomplete = true;
}
};
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/83060.html
標籤:HTML5
