猜点子的小游戏
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
.font1{
color:#3FC
}
.font2{
color:#F00;
}
</style>
</head>
<body οnlοad="demo()">
<script type="text/javascript" >
var b = true;
function demo()
{
var obj = document.getElementById("divid");
//alert(obj.tagName);
//alert(obj.innerText);
//obj.innerText = "kkkkkk";
if(b){
obj.className = "font1";
b = false;
}
else{
obj.className = "font2";
b = true;
}
setTimeout("demo()",500);
}
var num = parseInt(Math.random()*100+1);
document.getElementById("divid").innerText = num;
function guess()
{
var younum = parseInt(document.getElementById("tex").value);
if(younum == num)
{
document.getElementById("divid").innerText = "你猜的数字是"+younum+",恭喜你猜中了!";
}
else if(younum>num){
document.getElementById("divid").innerText = "你猜的数字是"+younum+",太大了!";
}
else{
document.getElementById("divid").innerText = "你猜的数字是"+younum+",太小了!";
}
document.getElementById("tex").value = "";
document.getElementById("tex").focus();
}
</script>
<b>请输入1-100的数字:</b>
<input type="text" id="tex" />
<input type="button" value="我猜" οnclick="guess()" />
<div id="divid">
hhha
</div>
</body>
</html>