前端之家收集整理的这篇文章主要介绍了
怎样用angular写一个倒计时10秒,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<title>倒计时</title>
<script type="text/javascript" src='../angularJs/angular-1.2.13/angular.min.js'></script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="firstController">
<input type="button" ng-value ="text" ng-disabled="isDisable"/>
<input type="text" value="{{text}}" ng-readonly="isDisable" />
<input type="checkBox" value="{{text}}" ng-checked="isDisable" />
</div>
</div>
</body>
<script type="text/javascript">
var app = angular.module("myApp",[]);
app.controller('firstController',['$scope','$interval',function ($scope,$interval) {
$scope.n = 10;
$scope.text = $scope.n + "秒";
$scope.isDisable = true;
var time = $interval(function () {
$scope.n--;
$scope.text = $scope.n + "秒";
if ($scope.n == 0)
{
$interval.cancel(time);
$scope.isDisable = false;
$scope.text = "可以点击";
}
},1000);
}]);
原文链接:https://www.f2er.com/angularjs/146024.html