Home >Web Front-end >JS Tutorial >JavaScript实现弹出广告功能代码

JavaScript实现弹出广告功能代码

PHP中文网
PHP中文网Original
2017-04-18 17:39:413835browse

本文通过实例代码给大家分享javascript实现弹出广告功能,代码简单易懂,非常不错,具有参考借鉴价值,需要的朋友参考下吧

废话不多说了,直接给大家贴代码了,具体代码如下所示:


<span style="white-space:pre"> </span>var i=0;//记录次数 
  var timer;//定时器id 
  //设置弹出广告 
  onload=function(){ 
  //间隔四秒展示一次广告 
  timer = setInterval(showAd,4000);   
  } 
  //展示2秒以后隐藏广告的方法 
  function showAd(){ 
    i++;//展示的次数加1 
    //若i等于3清空由setInterval设置的定时器 
    if(i==3){ 
      clearInterval(timer); 
    } 
    //1.获取广告 
    var pObj = document.getElementById("ad"); 
    //2,修改广告的样式 
    pObj.style.display="block"; 
    //两秒之后隐藏 
    setTimeout(hiddAd,2000); 
  } 
  //隐藏广告 
  function hiddAd(){ 
    var pObj = document.getElementById("ad"); 
    pObj.style.display="none"; 
  }
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn