(jQuery) 当到达到期日期/时间时显示和隐藏 div
<div class="info">
TEXT still showing
</div>
<div class="timeout">
TEXT (with display:none)
</div>
4月8日晚上10:00时 “信息”将隐藏 和 “timeout”的文本将显示
GMT +1
非常感谢
<div class="info">
TEXT still showing
</div>
<div class="timeout">
TEXT (with display:none)
</div>
When 10:00pm 8.Apr
"info" will hide
and
"timeout"s text will show
GMT +1
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
像这样的东西会起作用:
我不熟悉javascript日期函数,所以我用谷歌搜索了这个并使用了 w3c 和 本文 生成此答案
something like this would work:
I'm not familiar with javascript date functions so I googled this and used a mixture of w3c and this article to generate this answer
您需要使用 setInterval 每秒检查现在是什么时间。请记住它将使用客户端时间。更好的方法是使用服务器时间来获取经过时间的持续时间,并在 setInterval 中设置该持续时间以显示隐藏 div。
you need to use setInterval to check every second what time it is. Remember it will use client side time. Better way is to use server time to get the duration of elapsed time and set that duration in setInterval to show hide the div.
你需要的是两件事:
var targetTime = new Date(2011, 4, 8, 22, 0, 0);//22 意味着 22:00 ant即晚上 10 点(12 个小时)
var currentTime = new Date();
var targetMilliSeconds = targetTime.getTime();
var currentMilliSeconds = currentTime.getTime();
if ((currentMilliSeconds - targetMilliSeconds) == 0) { /你想做什么/ }
what you need is two things:
var targetTime = new Date(2011, 4, 8, 22, 0, 0);//22 means 22:00 ant that is 10 p.m (12 hours few)
var currentTime = new Date();
var targetMilliSeconds = targetTime.getTime();
var currentMilliSeconds = currentTime.getTime();
if ((currentMilliSeconds - targetMilliSeconds) == 0) { /what ever you want to do/ }