我在js中构建了倒计时功能,div显示了显示跳过按钮的秒数,但是innerHTML只显示文本,因此链接不可点击。
倒计时功能:
<div id="strclock"> Clock Here!</div>
<script type="text/javascript">
var hour = <?php echo floor($hours); ?>;
var min = <?php echo floor($minutes); ?>;
var sec = <?php echo floor($seconds); ?>;
var skip = "<a href='google.com'><img src='images/delicious_32.png'/></a>";
function countdown() {
if(sec <= 0 && min > 0) {
sec = 59;
min -= 1;
}else if(min <= 0 && sec <= 0) {
min = 0;
sec = 0;
}else {
sec -= 1;
}
if(min <= 0 && hour > 0) {
min = 59;
hour -= 1;
}
var pat = /^[0-9]{1}$/;
if(min > 0 || hour > 0){
sec = (pat.test(sec) == true) ? '0' + sec : sec;
}
min = (pat.test(min) == true) ? '0' + min : min;
hour = (pat.test(hour) == true) ? '0' + hour : hour;
document.getElementById('strclock').innerHTML = ".המתן " + sec + " שניות";
setTimeout("countdown()",1000);
if(sec <= 0){
document.getElementById('strclock').innerHTML = skip;
}
}
countdown()
</script>
我尝试使用jquery append()函数和其他一些javascript函数,但没有任何效果。
答案 0 :(得分:0)
您需要将函数作为第一个参数传递给document.setTimeout
试试这个:setTimeout(countdown,1000);