<pre>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script language="JavaScript">
var
hiddenRandom;
function func2() {
hiddenRandom = Math.ceil(Math.random() * 100);
document.getElementById("oneRandom").value = hiddenRandom;
}
function func1() {
var
oneRandom = document.getElementById("oneRandom").value;
if (hiddenRandom > oneRandom) {
alert("太小了");
}
else if (hiddenRandom < oneRandom) {
alert("太大了");
}
else {
alert("猜中了");
}
}
</script>
</head>
<body onload="func2()">
<form name="myFrm">
你猜一个数字(1-100):
<input type="text" id="oneRandom" size="12"/>
<br/>
<input type="button" value="计算" onclick="func1()"/>
</form>
</body>
</html>
</pre>
[此贴子已经被作者于2015-05-26 12:12:26编辑过]