<!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.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.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>
前端_张三、李四掷骰子
最新推荐文章于 2024-04-03 07:35:18 发布