1
我正在寫一個簡單的角度js應用程序。 但我很新的角js。提示框如果條件匹配角js
應用程序要求的答案爲2號
我想,當按鈕「檢查」被點擊時,函數應該檢查如果答案是正確的乘法。 如果回答錯誤,只有它應該顯示警報消息。
如何使用角度js來做到這一點?
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $window) {
$scope.firstname = "John";
$scope.showTable = false;
$scope.changeName = function() {
$scope.firstname = $scope.table;
}
$scope.generateRandomNumber = function() {
$scope.Rn = Math.floor(Math.random() * 31);
$scope.showTable = true;
}
$checkAnswer = function() {
//if ($scope.Rn * $scope.table == $scope.answer)
$window.alert("Right!");
// return;
}
$scope.randomNumber = function() {
$scope.firstname = Math.floor(Math.random() * 31);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<label>
Enter the table you want to practice :
</label>
<input type="text" ng-model="table" />
<button ng-click="generateRandomNumber()">
Start</button>
<h1 ng-show="showTable">
{{table}} * {{Rn}} =
<input type="text" ng-model="answer" />
<button ng-click="checkAnswer()">
Check</button></h1>
</div>
</body>
</html>
感謝@initfail和glovas 。那真是愚蠢! – Dhanashree