By GokiSoft.com|
19:54 12/03/2022|
AngularJS
[Video] Bài tập - Xử lý event bằng AngularJS - C2110L
Bài tập - Xử lý event bằng AngularJS
#vidu.html
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Calculator Online</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<style type="text/css">
.form-group {
margin-bottom: 20px;
}
</style>
</head>
<body ng-controller="MyController">
<div class="container">
<div class="card">
<div class="card-header bg-info">
GIAI PHUONG TRINH BAC 1
</div>
<div class="card-body">
<button class="btn btn-info" ng-click="nhapA()">Nhap A</button>
<button class="btn btn-info" ng-click="nhapB()">Nhap B</button>
<button class="btn btn-warning" ng-click="ketqua()">In Ket Qua</button>
</div>
</div>
</div>
<script type="text/javascript">
var app = angular.module('MyApp', [])
app.controller('MyController', ['$scope', function ($scope) {
$scope.a = 0
$scope.b = 0
$scope.nhapA = function() {
$scope.a = prompt("Nhap A", 0)
}
$scope.nhapB = function() {
$scope.b = prompt("Nhap B", 0)
}
$scope.ketqua = function() {
if($scope.a == 0) {
if($scope.b == 0) {
alert('PT VSN')
} else {
alert('PT VN')
}
} else {
var x = -$scope.b / $scope.a
alert('X = ' + x)
}
}
}])
</script>
</body>
</html>
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)