php-jQuery;单击以显示html内容和倒计时,然后显示其他内容
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php-jQuery;单击以显示html内容和倒计时,然后显示其他内容,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1477字,纯文字阅读大概需要3分钟。
内容图文
![php-jQuery;单击以显示html内容和倒计时,然后显示其他内容](/upload/InfoBanner/zyjiaocheng/656/04d7ff8852f74956a6c30c88d57da723.jpg)
我想创建一个链接,该链接将在我的论坛上显示直接链接之前显示内容.
>显示链接以下载附件
>点击后,它会在下面显示5秒倒计时的html内容
>倒数结束后,将显示直接链接.
我尝试了以下代码:
$("button").click(function() {
$(function() {
var count = 10;
countdown = setInterval(function() {
$("p.countdown").html(count + " seconds remaining!").show("slow");
if (count == 0) {
$("p.new").show("slow");
}
count--;
}, 1000);
});
});
解决方法:
魔术功能呢?
要谈论@Bradley Foster的答案,多次调用setTimeout是不可靠的.如果浏览器滞后,则setTimeout将停止,因此,如果有四种不同的设置,则不确定顺序是否正确.我在那里展示时嵌套setTimeout更好.
$('#button').click(function() {
var seconds = 5, // Declare some variables for reuse
el = $('#some_link')
el.text(seconds) // Put it a five!
// Name your function so that you can call it later
setTimeout(function countdown() {
// Your countdown is already at 5, so decrement it
// Remember that you've already waited for 1000ms before reaching this line the first time
seconds--
el.text(seconds) // Set the new time left
// If the countdown is not over, recall this function after 1000ms
if (seconds > 0) {
setTimeout(countdown, 1000)
}
// If it is over, display the link
// Note that js will stop there and not try to call itself another time as it would with setInterval()
else {
el.html('<a href="link">Download</a>')
}
}, 1000)
})
顺便说一句,在您的问题中,当您执行$(function(){…时,您实际上正在执行$(document).ready(function(){….我想这不是您想要的: )
Jsfiddle此处:http://jsfiddle.net/Ralt/kTbcm/
内容总结
以上是互联网集市为您收集整理的php-jQuery;单击以显示html内容和倒计时,然后显示其他内容全部内容,希望文章能够帮你解决php-jQuery;单击以显示html内容和倒计时,然后显示其他内容所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。