记录按钮点击次数,点击三次之后跳转页面

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="myApp" ng-controller="personCtrl">

<button ng-click="toggle()">点击</button>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
var submitml=0;  //(设置变量,初始为0)
$scope.toggle = function() {
submitml++;    //(当点击一次按钮,自加一)
if(submitml<3)
{
alert(submitml)
}else
{
window.location.href='http://www.baidu.com';
}
};
});
</script>

</body>
</html>

posted @ 2017-12-14 11:44  诗为马  阅读(1242)  评论(0编辑  收藏  举报