1-20之间随机生成数字,不断的在页面上进行滚动显示
然后按停止,就停止,比如停止在15
然后再按开始就再抽,但是不能再抽到15了,就在1-14,16-20中进行抽取应该怎么做,着急
解决方案 »
- 急救 如何设置div 遮罩层覆盖全部网页
- EXT的Window能像对话框那样中断吗?
- Open的小问题
- 父页面关闭子页面问题..帮我看一下..10分钟等待.
- 如何只让一个城市访问网站(最好精确到区),并且在某个时间段才能访问 不是这个城市的弹出消息,您不在服务区!(就是限制时间和地点访
- <iframe ID="Editor" MARGINHEIGHT="1">,Editor中的内容是完整的html页面内容,怎么完整地取得?
- 选择题
- 如何实现隐藏页
- 各位高手,帮小妹一下 ,我想实现在编辑word文档完成后关闭文档时不出现弹出请求保存窗口,而是自动保存在C:\temp目录下
- 请问一下怎么往infoTemplate里添加图片展示啊
- 求一个严格验证身份证号码的函数!!
- 求一些Javascript的好书
<!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 type="text/css">
html, body{
padding:0px; margin:0px; font-size:12px;
}
body{
margin:50px;
}
#result{
height:20px; margin-bottom:10px;
}
#result div{
float:left; border:1px solid #006699; color:#c00; width:24px; height:20px; line-height:20px;
margin-right:15px; text-align:center;
}
#control div{
float:left; width:24px; height:20px; line-height:20px; border:1px solid #008800; color:#c00;
margin-right:20px; text-align:center;
}
</style>
<script type="text/javascript">
var arrData = [], timerID = 0;
for(var i = 1; i <=20; i++){
arrData[i - 1] = i;
}
function $(id){
return document.getElementById(id);
}
function Start(btn){
if(timerID > 0){
clearInterval(timerID);
timerID = 0;
}
if(arrData.length < 1){
alert("没有数据了!");
return;
}
if(btn.value == "开始"){
timerID = setInterval(function(){
$("num").index = parseInt(Math.random() * (arrData.length - 1));
$("num").innerHTML = arrData[$("num").index];
}, 30);
btn.value = "暂停";
}else{
var div = document.createElement("div");
div.innerHTML = $("num").innerHTML;
$("result").appendChild(div);
arrData.splice($("num").index, 1);
btn.value = "开始";
}
}
window.onload = function(){
$("btnStart").focus();
};
</script>
</head><body>
<div id="result"></div><div style="clear:both; float:none"></div>
<div id="control">
<div id="num">0</div>
<input type="button" id="btnStart" value="开始" onclick="Start(this)" />
</div>
</body>
</html>
有个地方没搞好:
$("num").index = parseInt(Math.random() * (arrData.length - 1));
改成
$("num").index = parseInt(Math.random() * (arrData.length));
<html>
<head>
<title>身份证号是否有效验证 </title>
<script>
var old = new Array();
function getm()
{
return parseInt(Math.random()*(21-1)+1);
}
var newm;
function getMM()
{
newm = getm();
if(old.length==0)
{
old.push(newm);
return newm;
}
if(old.length>=20)
{
return '抽完了';
}
for(var i=0,len=old.length;i<len;i++)
{
if(old[i]==newm)
{
return getMM();
}
}
old.push(newm);
return newm;
}
</script>
</head>
<body>
<input type="button" value="抽" onclick="alert(getMM())"/>
</body>
</html>
<div id="div1"></div>
<input id="cmdStart" type="button" value="开始" />
<input id="cmdStop" type="button" value="停止" /> var timeHandle, data, index;
function cq() {
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
index = Math.round(Math.random() * 19);
document.getElementById('div1').innerHTML = data[index];
timeHandle = setTimeout(cq, 500);
}
document.getElementById('cmdStart').onclick = function() {
if(data.length == 0) {
alert('没有数据了!');
return;
}
timeHandle = setTimeout(cq, 500);
}
document.getElementById('cmdStop').onclick = function() {
clearTimeout(timeHandle);
data.splice(index, 1);
}
数组是从0开始索引的,data[19] = 20 啊