Angular 的掷骰子比赛的思想

来源:互联网 发布:java用类输出学生信息 编辑:程序博客网 时间:2024/06/01 10:42
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <script src="../angular-1.5.5/angular.min.js"></script>    <script>        var myapp=angular.module("myapp",[]);        myapp.controller("myCtrl",function($scope){            /* $scope.fun=function(){             $scope.guess=function(){             $scope.random1=parseInt(Math.random()*6);               $scope.random2=parseInt(Math.random()*6);              if($scope.random1>$scope.random2){             $scope.win="张三"             }else if($scope.random1<$scope.random2){             $scope.win="李四"             }else{             $scope.win="平局"             }             };             };             $scope.fun2=function(){             $scope.guess=function(){             /!* $scope.random1=parseInt(Math.random()*6);*!/             $scope.random2=parseInt(Math.random()*6);             if($scope.random1>$scope.random2){             $scope.win="张三"             }else if($scope.random1<$scope.random2){             $scope.win="李四"             }else{             $scope.win="平局"             }             };             };*/            $scope.guess=function(){                $scope.random1=parseInt(Math.random()*6);                $scope.random2=parseInt(Math.random()*6);                console.log( $scope.random1);                if($scope.random1>$scope.random2){                    $scope.win="张三"                }else if($scope.random1<$scope.random2){                    $scope.win="李四"                }else{                    $scope.win="平局"                }            };            $scope.no=function(){                $scope.random1=null;                $scope.random2=null;                $scope.win=null;            };        })    </script></head><body ng-app="myapp" ng-controller="myCtrl">张三<input type="text" value="" ng-model="random1" ng-click="fun()"><br/>李四<input type="text" value="" ng-model="random2" ng-click="fun2()"><br/><input type="text" ng-model="win">获胜者<br/><button ng-click="guess()">掷骰子</button><button ng-click="no()">不玩了</button></body></html>

原创粉丝点击