-4

我在 jQuery 中建立了一个倒计时,所以倒计时将从 5 减到 0,当它达到 0 时会显示警报。现在我想显示一个动态图像而不是那个警报。

所以这是我的计时器/jQuery代码

<script>
window.onload = function(){
    (function(){
            var counter = 5;    
            setInterval(function() {
                counter--;
                if (counter >= 0) {
                    span = document.getElementById("count");
                    span.innerHTML = counter;
                }
                // Display 'counter' wherever you want to display it.
                if (counter === 0) {
                    alert('this is where it happens');
                    clearInterval(counter);
                }
            }, 1000);
        })();
}
</script>

所以现在我需要它显示的不是警报:

<div style="float: right; display: inline-block; margin: 6px;">
    <div class="skip_btn">
        <a href="<?php echo $long_url2 ;?> ">SKIP AD &gt;&gt;</a>
    </div>
</div>
<div style="clear:both;"></div>

有没有办法做到这一点?

4

1 回答 1

0

像这样的工作吗?

<script>
window.onload = function(){

(function(){
  var counter = 5;

  setInterval(function() {
    counter--;
    if (counter >= 0) {
      span = document.getElementById("count");
      span.innerHTML = counter;
    }
    // Display 'counter' wherever you want to display it.
    if (counter === 0) {

        alert('this is where it happens');
        document.getElementById( "response" ).innerHTML = "<div style=\"float: right; display: inline-block; margin: 6px;\"><div class=\"skip_btn\"><a href=\"PHP?\">SKIP AD &gt;&gt;</a></div></div><div style=\"clear:both;\"></div>";
        clearInterval(counter);
    }

  }, 1000);

})();

}
</script>
<div id="count"></div>
<div id="response"></div>

它显示在响应元素中。我从链接中删除了你的 php 代码,因为我不知道它来自哪里,但你仍然可以像这样使用它

document.getElementById( "response" ).innerHTML = "<div style=\"float: right; display: inline-block; margin: 6px;\"><div class=\"skip_btn\"><a href=\"<?php echo $url;?>\">SKIP AD &gt;&gt;</a></div></div><div style=\"clear:both;\"></div>";
于 2012-12-03T11:17:52.383 回答