如何让它不重复出现,求大神帮助 请问你指的是不重复出现是什么意思呢?index = Math.floor(Math.random() * tips. length);这段代码有什么含义吗?还有你是想得到tips数组中的一个呢?还是逗得到? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主用cookie试试。<!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> </head> <body> <script Language="JavaScript"> function setCookie(name, value) { var exp = new Date(); exp.setTime(exp.getTime() + 20 * 1000); //cookie 保存20秒 document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); document.cookie = name + "=" + value; } function getCookie(name) { var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)")); if (arr != null) return unescape(arr[2]); return ''; } function delCookie(name)//删除cookie { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval = getCookie(name); if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); } function hasEmpty(){ //判断数组元素是否还存在没存到cookie里的。 for(i=0;i<9;i++){ if(getCookie(i) == ''){ return true; } } } tips = new Array(9); tips[0] = "金麟岂是池中物(1)"; tips[1] = "一遇风云变化龙(2)"; tips[2] = "左青龙(3)"; tips[3] = "右白虎(4)"; tips[4] = "前朱雀(5)"; tips[5] = "后玄武(6)"; tips[6] = "老牛在腰间(7)"; tips[7] = "床前明月光(8)"; tips[8] = "飞流直下三千尺(9)"; while(hasEmpty()) { index = Math.floor(Math.random() * tips.length); if (getCookie(index) == '') { setCookie(index, index); document.write("<FONT SIZE=8 COLOR=DARKBLUE>" + tips[index] + "</FONT>"); break; } } </Script> </body></html> 请教一个gson转换的问题 js里面怎样获取一个变量的值的前4位了? 可能是老题目,模型是购物车模式的,怎么去掉重复选择的物品?? 求助:第四类驱动 URL 问题 spring中jms的问题 数据库连接问题请教 寻找jsp空间 无声仿有声 飞碟 收分 :) 那位高手知道,用tomcat+jsp与mysql连接的必要条件是什么呀,谢谢了 第一条记录跑哪了 ? javascript能调用oracle存储过程么? 如何获取StringBuffer中有多少个“\n”?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head> <body>
<script Language="JavaScript">
function setCookie(name, value) {
var exp = new Date();
exp.setTime(exp.getTime() + 20 * 1000);
//cookie 保存20秒
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
document.cookie = name + "=" + value;
} function getCookie(name) {
var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
if (arr != null)
return unescape(arr[2]);
return '';
} function delCookie(name)//删除cookie
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if (cval != null)
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
function hasEmpty(){ //判断数组元素是否还存在没存到cookie里的。
for(i=0;i<9;i++){
if(getCookie(i) == ''){
return true;
}
}
}
tips = new Array(9);
tips[0] = "金麟岂是池中物(1)";
tips[1] = "一遇风云变化龙(2)";
tips[2] = "左青龙(3)";
tips[3] = "右白虎(4)";
tips[4] = "前朱雀(5)";
tips[5] = "后玄武(6)";
tips[6] = "老牛在腰间(7)";
tips[7] = "床前明月光(8)";
tips[8] = "飞流直下三千尺(9)"; while(hasEmpty()) {
index = Math.floor(Math.random() * tips.length);
if (getCookie(index) == '') {
setCookie(index, index);
document.write("<FONT SIZE=8 COLOR=DARKBLUE>" + tips[index] + "</FONT>");
break;
}
}
</Script>
</body>
</html>