<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DEMO</title>
<script type="text/javascript">
var gen;
function nandu(){
var xishu=document.getElementById('grade').value;
gen=Math.floor(Math.random()*xishu);
console.log(xishu);
console.log(gen);
}
function caishu(){
var result=document.getElementById("cai").value;
var msg;
if(gen>result){
msg='small';
}else if(gen==result){
msg='right';
}else if(gen<result){
msg='big';
}
document.getElementById("result").innerHTML=msg;
}
</script>
<style type="text/css">
#lg{
font-size: 32px;
font-weight: 800;
}
</style>
</head>
<body>
<div id="lg">
猜数字小游戏
</div>
<div id="head">
<p>请选择游戏难度</p>
<select id="grade">
<option value="10">简单</option>
<option value="100">一般</option>
<option value="1000">较难</option>
<option value="10000">抓狂</option>
</select>
<input type="button" value="确认" onclick="nandu()"/>
<p>请输入你所猜的数字</p>
<input type="number" id="cai"/>
<input type="button" name="" id="" value="猜数" onclick="caishu()"/>
<span id="result">
</span>
</div>
</body>
</html>
猜数字小游戏
最新推荐文章于 2024-11-16 14:11:26 发布