在逛一些商城类网站我们会发现很多商品秒杀广告多少时间会自动切换下一个,想实现这种效果我们可以用js判断当天时间段来显示不同广告。

var h = new Date().getHours();
var t = "";
if(h >= 6 && h <= 12){
        t = "广告1";        
}else if(h >= 14 && h <= 20){
        t = "广告2";
}
  else if(h >= 21 || h <= 6){
        t = "广告3";
  }
document.getElementById('time_ads').innerHTML = t;

PS:当天上午6点到12点显示广告1,下午14点到20点显示广告2,晚上19点到次日6点显示广告3

代码二

<script type="text/javascript">
var h = new Date().getHours();
var t = "";
if(h >= 7 && h <= 13){
        t = "<div class='inde_t_ad'><a href='http://www.moyublog.com/' target='_blank' rel='nofollow'><img src='/skin/add/a1.jpg' border='0' /></a></div>";        
}else if(h >= 14 && h <= 20){
        t = "广告2";
}
  else if(h >= 21 || h <= 6){
        t = "广告3";
  }
document.getElementById('time_ads').innerHTML = t;
</script>

广告代码分时段显示
早7点到13点显示广告1
14点到20点显示广告2
19点到次日6点显示广告3

测试时可以调整电脑时间。

原文地址:https://www.556z.com/post/4068.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
猜你喜欢
  • 1970-01-01
  • 2022-12-23
  • 2021-10-26
  • 2022-03-04
  • 1970-01-01
  • 2020-05-31
  • 2021-07-05
相关资源
相似解决方案