<html>
<head>
<title>猜数字游戏</title>
<script language="javascript">
<!--
n = Math.floor(Math.random() * 100);
function numGame(){
num = form.num.value;
str = "";
s = "你输入的数字";
if(num < 0 || num > 99){
str = s + "请输入一个0~99之间的整数";
}else{
if (num > n) str = s + "太大了";
if (num < n) str = s + "太小了";
if (num == n) {
str = "恭喜你猜对了!";
alert(str);
}
}
form.info.value = str;
}
//-->
</script>
</head>
<body>
<form name="form">
请输入一个(0~99)之间的整数:
<input type="text" name="num" size="3">
<input type="button" value="我猜" onClick="numGame()"><br>
信息:<input type="text" name="info" size="40">
</form>
</body>
</html>
<head>
<title>猜数字游戏</title>
<script language="javascript">
<!--
n = Math.floor(Math.random() * 100);
function numGame(){
num = form.num.value;
str = "";
s = "你输入的数字";
if(num < 0 || num > 99){
str = s + "请输入一个0~99之间的整数";
}else{
if (num > n) str = s + "太大了";
if (num < n) str = s + "太小了";
if (num == n) {
str = "恭喜你猜对了!";
alert(str);
}
}
form.info.value = str;
}
//-->
</script>
</head>
<body>
<form name="form">
请输入一个(0~99)之间的整数:
<input type="text" name="num" size="3">
<input type="button" value="我猜" onClick="numGame()"><br>
信息:<input type="text" name="info" size="40">
</form>
</body>
</html>