本文實(shí)例為大家分享了angular.js數(shù)字猜大小的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>猜大小</title> <script src="angular-1.5.5/angular.min.js"></script> <style> *{ margin:0; padding:0; font-size: 30px; } input{ width: 500px; height: 50px; } button{ width: 80px; height: 50px; border: 0; text-align: center; line-height: 50px; color: white; margin-left: 5px; } </style> <script> var m=angular.module("m",[]); m.controller("my",function ($scope) { $scope.check=function () { $scope.differ=$scope.guess-$scope.random; $scope.num++; } $scope.reset=function () { $scope.guess=null; $scope.differ=null; $scope.num=0; $scope.random=Math.ceil(Math.random()*10); } $scope.reset(); }) </script></head><body ng-app="m" ng-controller="my"><h1>請(qǐng)輸入一個(gè)1-10的整數(shù)</h1> <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">猜對(duì)了</p> <p>你一共才了<span ng-bind="num">0</span>次</p></body></html>以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持錯(cuò)新站長(zhǎng)站。
新聞熱點(diǎn)
疑難解答
圖片精選