我遇到了一個場景,我需要在用戶點擊鏈接後開始倒計時,但在此之前,數字「10」(十秒倒數)必須可見。鏈接本身也打開另一頁。倒計時它不應該在最後做任何事情,只是裝飾。我該如何解決這個問題?如何在用戶點擊鏈接時設置倒計時?
<div id="gatewayDimmer"> </div>
<div id="gatewaydiv">
<ul id="OfferList">
<h1>Ayudanos a mantener la Página</h1>
<span id="gatewayMessage">Hicimos esta página de onda. Y no se mantiene sola! Ayudanos clickeando en la publicidad.</span> <br />
<br />
<li><a href="http://www.wachahost.com" class="offerlink" target="blank">Cheap Web Hosting</a></li>
<li><a href="http://peerfly.com/x/0/1076/3696/" class="offerlink" target="blank">Free Apple Ipad</a></li>
<li><a href="http://www.google.com" class="offerlink" target="blank">Google</a></li>
</ul>
<br />
<br />
Luego de completar la oferta espera: <span id="count">10</span> segundos <script type="text/javascript">
{
(function countDown(){
var counter = 10;
setInterval(function countDown() {
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> para acceder a la página.<br />
Gracias!</div>
消息腳本:
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script> <script type="text/javascript">
var Delay = 10;
function setupgateway()
{
var Left = $(window).width() /2;
Left = Left - $('#gatewaydiv').width()/2;
var Top = $(window).height() /2;
Top = Top - $('#gatewaydiv').height()/2;
$('#gatewaydiv').css('top', Top+'px').css('left', Left+'px').css('display', 'inline');
$('#gatewayDimmer').width($('html').width());
$('#gatewayDimmer').height($('html').height());
$('#gatewayDimmer').css('display','block');
}
function removegateway()
{
$('#gatewaydiv').css('display', 'none');
$('#gatewayDimmer').css('display','none');
}
$(document).ready(function()
{
$('.offerlink').click(function()
{
setTimeout('removegateway()', Delay*1000);
});
setupgateway();
});
</script>
[Java腳本,倒數計時器和顯示文本(的可能的複製HTTPS ://stackoverflow.com/questions/9989285/javascript-countdown-timer-and-display-text) – Ivar
不,不。我不想在最後顯示文本。只是倒計時。另外,它需要在點擊鏈接後啓動。 –
什麼倒計時?如果我不可見並且最終沒有做任何事情,那麼倒計時有什麼用? – Ivar