五个领导,每个领导做成一张图片,一天显示一张,自动循环!以前是文字的值班表,现在想改成图片的!
请问如何修改?
<script>
function getDateDiff(date1,date2){
   var   re   =   /^(\d{4})\S(\d{1,2})\S(\d{1,2})$/;   
   var   dt1,dt2;   
   if   (re.test(date1))   
   {   
    dt1   =   new   Date(RegExp.$1,RegExp.$2   -   1,RegExp.$3);   
   } 
    
   if   (re.test(date2))   
   {   
    dt2   =   new   Date(RegExp.$1,RegExp.$2   -   1,RegExp.$3);   
   }  
    
   return Math.floor((dt2-dt1)/(1000 * 60 * 60 * 24))
   
  } 
  
Date.prototype.format   =   function(format){   
      var   o   =   {   
          "M+"   :   this.getMonth()+1,   //month   
          "d+"   :   this.getDate(),         //day   
          "h+"   :   this.getHours(),       //hour   
          "m+"   :   this.getMinutes(),   //minute   
          "s+"   :   this.getSeconds(),   //second   
          "q+"   :   Math.floor((this.getMonth()+3)/3),     //quarter   
          "S"   :   this.getMilliseconds()   //millisecond   
      }   
      if(/(y+)/.test(format))   format=format.replace(RegExp.$1,   
          (this.getFullYear()+"").substr(4   -   RegExp.$1.length));   
      for(var   k   in   o)if(new   RegExp("("+   k   +")").test(format))   
          format   =   format.replace(RegExp.$1,   
              RegExp.$1.length==1   ?   o[k]   :     
                  ("00"+   o[k]).substr((""+   o[k]).length));   
      return   format;   
  };
</script>
</head>
<body>
<div align='center'>
<div id='name'>name</div>
</div>
</font>
<script>
var count = getDateDiff('2010-04-15', new Date().format("yyyy-MM-dd"))%5;
if(count == 0){
document.getElementById('name').firstChild.nodeValue = "领导1";
}else if(count == 1){
document.getElementById('name').firstChild.nodeValue = "领导2";
}else if(count == 2){
document.getElementById('name').firstChild.nodeValue = "领导3";
}else if(count == 3){
document.getElementById('name').firstChild.nodeValue = "领导4";
}else if(count == 4){
document.getElementById('name').firstChild.nodeValue = "领导5";
}
</script>

解决方案 »

  1.   

    那就用一个setTimeout 五天调用一次循环函数,在函数里写setTimeout 至于图片,那就调用路径就可以了,比如设置问temp1.png,temp2.png,temp3.png,调用一次函数,i++;图片的路径换一个就可以了
      

  2.   

      function showPic(name){
      var img= document.createElement("img");
      img.setAttribute("src",name);
      document.getElementById("name").appendChild(img);
      }
    <div id='name'></div>
    <script>
    var count = getDateDiff('2010-05-29', new Date().format("yyyy-MM-dd"))%5;
    if(count == 0){
    showPic("http://www.gov.cn/gjjg/images/images/00188b27c9090945a55001_small.jpg");
    }else if(count == 1){
    showPic("http://www.gov.cn/gjjg/images/images/00188b27c9090946d9e60e_small.jpg");
    }else if(count == 2){
    showPic("http://www.gov.cn/gjjg/images/images/00188b27c9090945a51f01_small.jpg");
    }else if(count == 3){
    showPic("http://www.gov.cn/gjjg/images/images/0011431a94e609487b2601_small.jpg");
    }else if(count == 4){
    showPic("http://www.gov.cn/gjjg/images/images/0011431a94e609487a4601_small.jpg");
    }
    </script>
      

  3.   

    <html>
    <head>
    <script>
    function showPic(name){
      var img= document.createElement("img");
      img.setAttribute("src",name);
      document.getElementById("name").appendChild(img);
      }
      </script>
    </head><body>
    <div id='name'></div>
    <script>
    var count = getDateDiff('2010-05-29', new Date().format("yyyy-MM-dd"))%5;
    if(count == 0){
    showPic("http://www.gov.cn/gjjg/images/images/00188b27c9090945a55001_small.jpg");
    }else if(count == 1){
    showPic("http://www.gov.cn/gjjg/images/images/00188b27c9090946d9e60e_small.jpg");
    }else if(count == 2){
    showPic("http://www.gov.cn/gjjg/images/images/00188b27c9090945a51f01_small.jpg");
    }else if(count == 3){
    showPic("http://www.gov.cn/gjjg/images/images/0011431a94e609487b2601_small.jpg");
    }else if(count == 4){
    showPic("http://www.gov.cn/gjjg/images/images/0011431a94e609487a4601_small.jpg");
    }
    </script>
    </body>
    </html>图片还是不显示!
      

  4.   

    好像是这行代码有问题:
    var count = getDateDiff('2010-05-29', new Date().format("yyyy-MM-dd"))%5;
      

  5.   

     function showPic(name){
      var img= document.createElement("img");
      img.setAttribute("src",name);
      document.getElementById("name").appendChild(img);
      }
    这段代码加到日期处理那个<script></script>之间就行了。
      

  6.   


    <script>
    function getDateDiff(date1,date2){
     var re = /^(\d{4})\S(\d{1,2})\S(\d{1,2})$/; 
     var dt1,dt2; 
     if (re.test(date1)) 
     { 
      dt1 = new Date(RegExp.$1,RegExp.$2 - 1,RegExp.$3); 
     } 
      
     if (re.test(date2)) 
     { 
      dt2 = new Date(RegExp.$1,RegExp.$2 - 1,RegExp.$3); 
     }  
      
     return Math.floor((dt2-dt1)/(1000 * 60 * 60 * 24))
     

      
    Date.prototype.format = function(format){ 
      var o = { 
        "M+" : this.getMonth()+1, //month 
        "d+" : this.getDate(),   //day 
        "h+" : this.getHours(),   //hour 
        "m+" : this.getMinutes(), //minute 
        "s+" : this.getSeconds(), //second 
        "q+" : Math.floor((this.getMonth()+3)/3),   //quarter 
        "S" : this.getMilliseconds() //millisecond 
      } 
      if(/(y+)/.test(format)) format=format.replace(RegExp.$1, 
        (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
      for(var k in o)if(new RegExp("("+ k +")").test(format)) 
        format = format.replace(RegExp.$1, 
          RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
      return format; 
    };
    </script>
    </head>
    <body>
    <div align='center'>
    <div id='pic'><img id="photo" src=""></div><!-- 加了个放照片的div -->
    <div id='name'>name</div>
    </div>
    </font>
    <script>
    //照片路径数组
    var arr = new Array()
    arr = [
      "http://www.gov.cn/gjjg/images/images/00188b27c9090945a55001_small.jpg",
      "http://www.gov.cn/gjjg/images/images/00188b27c9090946d9e60e_small.jpg",
      "http://www.gov.cn/gjjg/images/images/00188b27c9090945a51f01_small.jpg",
      "http://www.gov.cn/gjjg/images/images/0011431a94e609487b2601_small.jpg",
      "http://www.gov.cn/gjjg/images/images/0011431a94e609487a4601_small.jpg"
    ];
    var count = getDateDiff('2010-04-15', new Date().format("yyyy-MM-dd"))%5;
    switch(count){
    case 0 :
    document.getElementById('name').firstChild.nodeValue = "领导1";
    case 1:
    document.getElementById('name').firstChild.nodeValue = "领导2";
    case 2:
    document.getElementById('name').firstChild.nodeValue = "领导3";
    case 3:
    document.getElementById('name').firstChild.nodeValue = "领导4";
    case 4:
    document.getElementById('name').firstChild.nodeValue = "领导5";
    default:
    document.getElementById("photo").src = arr[count];//给图片加路径
    }</script>
      

  7.   

    function showPic(name){
      var img= document.createElement("img");
      img.setAttribute("src",name);
      document.getElementById("name").appendChild(img);
      }