<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="../angular.min.js"></script> <script> var myapp=angular.module("myapp",[]); myapp.controller("myctrl",function ($scope) { $scope.check=function () { $scope.differ=Math.ceil(Math.random()*10); console.log($scope.differ); console.log($scope.guess); $scope.differ=$scope.guess-$scope.differ; $scope.number++; } $scope.reset=function () { $scope.guess=""; $scope.differ=null; $scope.number=0; } $scope.reset(); }) </script> </head> <body ng-app="myapp" ng-controller="myctrl"> <p>请输入一个1--10的数</p> <p>一共猜了{{number}}次</p> <input type="text" ng-model="guess"> <button ng-click="check()">检查</button> <button ng-click="reset()">重置</button> <p>我输入的是{{guess}},与系统匹配的相差{{differ}}</p> <p ng-if="differ>0">猜大了,小一点</p> <p ng-if="differ<0">猜小了,大点</p> <p ng-if="differ==0" style="color: red">恭喜你,你人品真好</p> </body> </html>
自定义的一种猜大小的游戏
最新推荐文章于 2024-08-09 16:47:53 发布