angularjs实现猜数字大小功能
时间:2021-08-22 09:50:21|栏目:AngularJS|点击: 次
本文实例为大家分享了angularjs实现猜数字大小功能的具体代码,供大家参考,具体内容如下
<body ng-app="myapp" ng-controller="myCtrl"> <h2>猜一猜,多大值?(1-1000)</h2> 我猜是:<input type="text" ng-model="guess"> <button ng-click="check()">验证</button><button ng-click="reset()">再玩一次</button><br> <span ng-if="fil>0">您猜的数大了</span> <span ng-if="fil<0">您猜的数小了</span> <span ng-if="fil==0">您猜对了</span> <p>猜的次数<span>{{n}}</span></p> </body>
js代码:
<script src="angular.min.js"></script> <script> var myapp=angular.module("myapp",[]); myapp.controller("myCtrl",function ($scope) { //验证 $scope.check=function () { console.log($scope.random); //根据差值判断显示、隐藏状态 $scope.fil=$scope.guess-$scope.random; $scope.n++; }; //重置方法 $scope.reset=function () { $scope.guess=null; $scope.fil=null; $scope.n = 0; //得到随机数 $scope.random=Math.ceil(Math.random()*1000); }; $scope.reset(); }) </script>
栏 目:AngularJS
下一篇:Angular8引入百度Echarts进行图表分析的实现代码
本文标题:angularjs实现猜数字大小功能
本文地址:http://www.codeinn.net/misctech/169057.html