求一段js代码,根据早晚时间改变图片
<styletype="text/css">#mg1{position:absolute;width:480px;height:205px;left:220px;top:...
<style type="text/css">
#mg1 {position:absolute; width:480px; height:205px; left:220px; top:125px;}
#mg2 {position:absolute; width:480px; height:205px; left:220px; top:125px; }
</style>
</head>
<body>
<div><img id="mg1" src="1.jpg" /></div>
<div><img id="mg2" src="2.jpg" /></div>
<script type="text/javascript">
window.onload = function() {
function ChangePic(){
var now = new Date()();
var curr_hour = now.getHours();
if(curr_hour >= 7 && curr_hour < 18)
{
document.getElementById("mg1").style.background = 'url(1.jpg)';
}
else
{
document.getElementById("mg2").style.background = 'url(2.jpg)';
}
};
ChangePic();
};
</script>
</body>
</html>
这是我自己修改的 但是修改时间,图片没有变化 展开
#mg1 {position:absolute; width:480px; height:205px; left:220px; top:125px;}
#mg2 {position:absolute; width:480px; height:205px; left:220px; top:125px; }
</style>
</head>
<body>
<div><img id="mg1" src="1.jpg" /></div>
<div><img id="mg2" src="2.jpg" /></div>
<script type="text/javascript">
window.onload = function() {
function ChangePic(){
var now = new Date()();
var curr_hour = now.getHours();
if(curr_hour >= 7 && curr_hour < 18)
{
document.getElementById("mg1").style.background = 'url(1.jpg)';
}
else
{
document.getElementById("mg2").style.background = 'url(2.jpg)';
}
};
ChangePic();
};
</script>
</body>
</html>
这是我自己修改的 但是修改时间,图片没有变化 展开
展开全部
<html>
<head>
<style type="text/css">
#mg1 {position:absolute; width:480px; height:205px; left:220px; top:125px;}
</style>
</head>
<body>
<div><img id="mg1" src="1.jpg" /></div>
<script type="text/javascript">
window.onload = function() {
function ChangePic(){
var now = new Date();
var curr_hour = now.getHours();
alert(curr_hour);
if(curr_hour >= 7 && curr_hour < 18)
{
document.getElementById("mg1").src = 'url(1.jpg)';
}
else
{
document.getElementById("mg1").src = 'url(2.jpg)';
}
};
ChangePic();
};
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询