本文实例讲述了AngularJS实现的生成随机数与猜数字大小功能。分享给大家供大家参考,具体如下:
创新互联公司专业为企业提供禹城网站建设、禹城做网站、禹城网站设计、禹城网站制作等企业网站建设、网页设计与制作、禹城企业网站模板建站服务,十余年禹城做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>www.jb51.net Angular猜数</title> <style> *{ margin: 0; padding: 0; font-size: 30px; } input{ width: 500px; height: 50px; font-size: 30px; } button{ width: 80px; height: 50px; border: 0; text-align: center; line-height: 50px; background: darkblue; color: #fff; margin-left: 5px; } </style> <script src="angular/angular.js"></script> <script> var myapp=angular.module("myapp",[]); myapp.controller("myCtrl",function ($scope) { $scope.check=function () { console.log($scope.random); $scope.differ=$scope.guess-$scope.random; $scope.num++; }; $scope.reset=function () { $scope.differ=null; $scope.guess=null; $scope.num=0; $scope.random=Math.ceil(Math.random()*10); }; $scope.reset(); }) </script> </head> <body ng-app="myapp" ng-controller="myCtrl"> <h3>请输入一个1-10的整数</h3> <input type="text" ng-model="guess"><button ng-click="check()">检查</button><button ng-click="reset()">重置</button> <p ng-if="differ>0">猜大了</p> <p ng-if="differ<0">猜小了</p> <p ng-if="differ==0">猜对了</p> <p>一共猜了<span ng-bind="num"></span>次</p> </body> </html>
运行效果:
PS:这里再为大家提供几款相关在线工具供大家参考:
在线随机数字/字符串生成工具:
http://tools.jb51.net/aideddesign/suijishu
在线随机字符/随机密码生成工具:
http://tools.jb51.net/aideddesign/rnd_password
高强度密码生成器:
http://tools.jb51.net/password/CreateStrongPassword
更多关于AngularJS相关内容感兴趣的读者可查看本站专题:《AngularJS指令操作技巧总结》、《AngularJS入门与进阶教程》及《AngularJS MVC架构总结》
希望本文所述对大家AngularJS程序设计有所帮助。
文章名称:AngularJS实现的生成随机数与猜数字大小功能示例
浏览地址:https://www.cdcxhl.com/article30/pcpeso.html
成都网站建设公司_创新互联,为您提供、网站收录、服务器托管、网站改版、建站公司、网站维护
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联