web程序设计 用JavaScript脚本语言设计一个程序:根据当天是星期几,在页面中显示不同的图片。
展开全部
<img id="img1" src="" /><br /><div id="day1"></div>
<script language="javascript" type="text/javascript">
day = new Date().getDay();
var pic_arr = new Array();
var i = 0;
pic_arr[i] = "0.jpg";//星期天的图片,以下类推
i++;
pic_arr[i] = "1.jpg";
i++;
pic_arr[i] = "2.jpg";
i++;
pic_arr[i] = "3.jpg";
i++;
pic_arr[i] = "4.jpg";
i++;
pic_arr[i] = "5.jpg";
i++;
pic_arr[i] = "6.jpg";
document.getElementById("day1").innerHTML = "今天星期" + "天一二三四五六".charAt(day);
document.getElementById("img1").src = pic_arr[day];
</script>
<script language="javascript" type="text/javascript">
day = new Date().getDay();
var pic_arr = new Array();
var i = 0;
pic_arr[i] = "0.jpg";//星期天的图片,以下类推
i++;
pic_arr[i] = "1.jpg";
i++;
pic_arr[i] = "2.jpg";
i++;
pic_arr[i] = "3.jpg";
i++;
pic_arr[i] = "4.jpg";
i++;
pic_arr[i] = "5.jpg";
i++;
pic_arr[i] = "6.jpg";
document.getElementById("day1").innerHTML = "今天星期" + "天一二三四五六".charAt(day);
document.getElementById("img1").src = pic_arr[day];
</script>
追问
为什么我的图片无法显示
追答
图片要换成你网站上的实际图片路径和名称,还有中间要设置图片的大小,这个大小也要根据你实际图片的大小来确定。写成其中width后面的引号内是宽度,height是高度。
以今天星期三为例,图片用百度的标志,写成:
day = new Date().getDay();
var pic_arr = new Array();
var i = 0;
pic_arr[i] = "0.jpg";//星期天的图片,以下类推
i++;
pic_arr[i] = "1.jpg";
i++;
pic_arr[i] = "2.jpg";
i++;
pic_arr[i] = "http://www.baidu.com/img/baidu_sylogo1.gif";
i++;
pic_arr[i] = "4.jpg";
i++;
pic_arr[i] = "5.jpg";
i++;
pic_arr[i] = "6.jpg";
document.getElementById("day1").innerHTML = "今天星期" + "天一二三四五六".charAt(day);
document.getElementById("img1").src = pic_arr[day];
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询