如何让它不重复出现,求大神帮助

赵麟宇 2014-03-17 09:51:41
<!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">
<!-->

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)";

index = Math.floor(Math.random() * tips. length);

document.write("<FONT SIZE=8 COLOR=DARKBLUE>" +tips[index]+"</FONT>");
</Script>
</body>
</html>
...全文
128 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
代号裤子 2014-03-18
  • 打赏
  • 举报
回复
楼主用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>
  • 打赏
  • 举报
回复
你写多少就显示多少
wyx100 2014-03-18
  • 打赏
  • 举报
回复
不重复,不可能啊
小小小伙 2014-03-18
  • 打赏
  • 举报
回复
请问你指的是不重复出现是什么意思呢?index = Math.floor(Math.random() * tips. length);这段代码有什么含义吗?还有你是想得到tips数组中的一个呢?还是逗得到?
S117 2014-03-18
  • 打赏
  • 举报
回复
每次加载页面都显示不同值,不重复?你认为这个可能吗?
tony4geek 2014-03-18
  • 打赏
  • 举报
回复
什么不重复出现,什么意思。
赵麟宇 2014-03-18
  • 打赏
  • 举报
回复
谢谢各位大神,我做出来了

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧