怎么才能让JS按顺序显示呢, 如:显示广告代码1刷新显示广告代码2.....5显示后再回到1如此循环 下面是找到的一个随机显示的广告~ 但是不知道怎么才能让他按1-5显示<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
///// 广告数 
shu = 5 
ad1=' <FONT color=#ff0000> </FONT>' 
//////// 广告内容 
theAds = new Array(); 
theAds[1] = '1                      '; 
theAds[2] = '2                      '; 
theAds[3] = '3'; 
theAds[4] = '4'; 
theAds[5] = '5'; 
sx = parseInt(Math.random() * shu + 1); 
document.write(ad1+theAds[sx]); 
--> </script> 

解决方案 »

  1.   


    <body>
    <div id=AD><FONT color=#ff0000> AD-1 </FONT></div>
    <SCRIPT LANGUAGE="JavaScript"> 
    <!-- 
    ///// 广告数 
    shu = 1 
    ad1='<FONT color=#ff0000> ' 
    ad2=' </FONT>' 
    //////// 广告内容 
    theAds = new Array(); 
    theAds[1] = 'AD-1'; 
    theAds[2] = 'AD-2'; 
    theAds[3] = 'AD-3'; 
    theAds[4] = 'AD-4'; 
    theAds[5] = 'AD-5';
    function doAD(){
    shu++
    if (shu>=theAds.length)shu=1
    document.getElementById("AD").innerHTML=ad1+theAds[shu]+ad1
    setTimeout(doAD,800)
    }
    setTimeout(doAD,1000)
    --> 
    </script> 
    </body>
      

  2.   

    说真的,把random去了应该差不多了,random就是随机的意思
      

  3.   

    <SCRIPT LANGUAGE="JavaScript"> 
    var ad1=' <FONT color=#ff0000> </FONT>' 
    var theAds = new Array("111","222","333","444","555")
    var rs=/IMGnum=\w+/.exec(document.cookie)
    if(rs==null)
    { document.cookie="IMGnum="+0
        document.write(ad1+theAds[0]); 
    }
    else
    {
    var num = parseInt(rs.toString().charAt(rs.toString().length-1));
    num=(num!=4?num+1:0);
    document.cookie="IMGnum="+num;
        document.write(ad1+theAds[num]); 
    }
    </script> 
      

  4.   

    var m=3; //共几个广告随机显示
    var n=Math.floor(Math.random()*m+1)
    switch(n)
    {  
    case 1: 
    document.writeln("1");
    break;
    case 2: 
    document.writeln("2");
    break;
    case 3: 
    document.writeln("3");
    break;
    }又找到一个比较简略的代码,不知道能不能 每次刷新的时候给N+1 大于3的时候再赋值0呢?
      

  5.   


    <body>
    <div id=AD><FONT color=#ff0000> AD-1 </FONT></div>
    <SCRIPT LANGUAGE="JavaScript"> 
    <!-- 
    function GetCookie(Name) {//读Cookie中Name的值
    var search = Name + "="
    var Cookie =document.cookie;
    if (Cookie.length <= 0 || Cookie.indexOf(search)==-1)return 0;// cookie 不存在 或 'shu' 不存在,返回 0
    else{
    var tmp= Cookie.split(search)[1].split(";")[0]
    return unescape(tmp)
    }
    }
    function SetCookie(id){//写Cookie
    document.cookie="num="+escape(id)
    }ad1='<FONT color=#ff0000> ' 
    ad2=' </FONT>' 
    //////// 广告内容 
    theAds = new Array(); 
    theAds[1] = 'AD-1'; 
    theAds[2] = 'AD-2'; 
    theAds[3] = 'AD-3'; 
    theAds[4] = 'AD-4'; 
    theAds[5] = 'AD-5';
    onload=function(){
    var shu=1
    var tmp=GetCookie('num');
    if (tmp)
    shu=parseInt(tmp)+1
    if (shu>=theAds.length)shu=1
    document.getElementById("AD").innerHTML=ad1+theAds[shu]+ad1
    document.cookie="num="+escape(shu)
    }
    --> 
    </script> 
    </body>