本文主要为大家详细介绍了angularjs实现猜大小功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能帮助大家。
本文实例为大家分享了angular.js数字猜大小的具体代码,供大家参考,具体内容如下
<!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>请输入一个1-10的整数</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">猜对了</p>
<p>你一共才了<span ng-bind="num">0</span>次</p>
</body>
</html>相关推荐:
以上就是angularjs实现猜大小功能详解的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号