【着急100分】求一个JavaSrcipt页面抽签的程序 1-20之间随机生成数字,不断的在页面上进行滚动显示然后按停止,就停止,比如停止在15然后再按开始就再抽,但是不能再抽到15了,就在1-14,16-20中进行抽取应该怎么做,着急 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!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 啊 关于jquery的一点问题 在线等答案 关于取消input框已绑定的事件 请大家帮我看看,我这断JS有没有错误 请问jquery除了not("[nodeType=1]")可以使用nodeTpye以外还有哪里可以使用? 这样js代码如何理解? php变量怎么传递给javascript? 各位GGJJ,小弟想问一下,在web页面上,怎么将鼠标的右键屏蔽掉???? 在网页中加载activex控件的问题 Java web jsp 数组里面有重复的数据 , 如何解决?代码已上[急] 求一个严格验证身份证号码的函数!! 求一些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 啊