想做一个图片的值班表,五天一个循环,循环已经写好,就是调用图片的问题!

xinyi1986001 2010-05-29 10:47:35
五个领导,每个领导做成一张图片,一天显示一张,自动循环!以前是文字的值班表,现在想改成图片的!
请问如何修改?
<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>

...全文
376 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
weiyingsong0221 2010-05-31
  • 打赏
  • 举报
回复
function showPic(name){
var img= document.createElement("img");
img.setAttribute("src",name);
document.getElementById("name").appendChild(img);
}
zyzy15 2010-05-31
  • 打赏
  • 举报
回复

<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>

ad0128 2010-05-31
  • 打赏
  • 举报
回复
 function showPic(name){
var img= document.createElement("img");
img.setAttribute("src",name);
document.getElementById("name").appendChild(img);
}

这段代码加到日期处理那个<script></script>之间就行了。
hnsxldj 2010-05-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 xinyi1986001 的回复:]

HTML code
<html>
<head>
<script>
function showPic(name){
var img= document.createElement("img");
img.setAttribute("src",name);
document.getElementById("name").appendChild(img);
}
</script>……
[/Quote]

把你开始贴的复杂的时间处理脚本再加进来就可以了。

给大领导们排班,你牛!
helloword222 2010-05-30
  • 打赏
  • 举报
回复
好像是这行代码有问题:
var count = getDateDiff('2010-05-29', new Date().format("yyyy-MM-dd"))%5;
xinyi1986001 2010-05-30
  • 打赏
  • 举报
回复
<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>




图片还是不显示!
ad0128 2010-05-29
  • 打赏
  • 举报
回复
  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>
passself 2010-05-29
  • 打赏
  • 举报
回复
那就用一个setTimeout 五天调用一次循环函数,在函数里写setTimeout 至于图片,那就调用路径就可以了,比如设置问temp1.png,temp2.png,temp3.png,调用一次函数,i++;图片的路径换一个就可以了
xinyi1986001 2010-05-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ad0128 的回复:]
HTML code
function showPic(name){
var img= document.createElement("img");
img.setAttribute("src",name);
document.getElementById("name").appendChild(img);
}



HTML code

<div id='……
[/Quote]

上面的部分放在需要调用的文件里还是与下面放在一个文件里?

87,910

社区成员

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

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