【问题标题】:Set a timeout before show a div在显示 div 之前设置超时
【发布时间】:2015-06-15 14:14:31
【问题描述】:

我有一个问题,我想在 5 秒后显示一个 div,我试过了:

if(obj.google_analytics.is_casino_game){
  setTimeout(function() { }, 500);
}
document.getElementById('addsense-pub').setAttribute('class','display-block');

但不起作用。你能帮我吗?提前谢谢

【问题讨论】:

    标签: javascript jquery jquery-ui javascript-events


    【解决方案1】:

    不确定我是否明白,但您至少必须将要执行的代码放在超时内

    if(obj.google_analytics.is_casino_game){
        setTimeout(function() {
            document.getElementById('addsense-pub').setAttribute('class','display-block');
        }, 5000);
    }
    

    请注意,以这种方式在 adSense 中隐藏和显示广告通常被视为违反 TOS

    【讨论】:

      【解决方案2】:

      在setTimeout函数()里面写代码

       setTimeout(function() { 
         $('#addsense-pub').show();
      
      }, 5000);
      

      【讨论】:

        【解决方案3】:

        你可以使用delay:

        if (obj.google_analytics.is_casino_game) {
            $('#addsense-pub').delay(5000).show();
            // Will add delay of 5 seconds before showing the element
        }
        

        文档:https://api.jquery.com/delay/

        使用setTimeout

        if (obj.google_analytics.is_casino_game) {
            setTimeout(function () {
                $('#addsense-pub').show();
            }, 5000);
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-10-30
          • 2023-03-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-02-18
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多