打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ColdFusion和html做的猜数字游戏
 

<script>

<cfset rn = RandRange(1, 10)>

<cfoutput>

var randomNumber = #rn#

</cfoutput>

var count = 1;

var maxCount = 3;

</script>

<script>

function check() {

if (count <= maxCount) {

var input = document.getElementById("guess").value;

if (input == randomNumber) {

alert("You got it. I picked " + randomNumber + "! Great job!");

self.location.href = "guess.cfm"

} else {

var information = "";

if(input < randomNumber) {

information = "You enter a less number."

} else {

information = "You enter a greater number."

}

if (count == 3) {

alert("Sorry, you got the max retry times.");

self.location.href = "guess.cfm"

} else {

info.innerHTML="<html><font color='red'><b>Sorry, you are wrong. There are " + (maxCount - count) + " times left! Try again!<br> " + information + "</b></font></html>";

}

}

count ++;

}

}

</script>

<html>

<head>

<title>Guess the number</title>

</head>

<body>

<b>Please enter number 1-10 to guess. There are 3 times for you!</b>

<form method="post">

<table>

<tr><td colspan="2"><span id="info"></span></td></tr>

<tr>

<td>Input the Number:</td>

<td><input type="text" id="guess"></td>

</tr>

<tr>

<td colspan="2" align="center"><input type="button" value="Guess" onclick="javascript: check()"></td>

</tr>

</table>

</form>

</body>

</html>

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
js抓取HTML的Table 并为表格里每个格赋值
留言板源代码
php用户注册页面使用js进行表单验证具体实例
table里每一行都有一个checkbox,选中一行后,怎么得到该行特定或者所有TD数据
动态生成HTML表单
动态增加删除表格行(兼容IE/FF)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服