在网页上加个距离某个时间剩余多少天的代码
1个回答
展开全部
<div class="er"> <br>欢迎参加第121届广交会,距离开幕还有
<span class="time">
<span id="t_d">00</span> 天
</span><br>
<script>
function GetRTime(){
var EndTime= new Date('2017/03/27 00:00:00');
var NowTime = new Date();
var t =EndTime.getTime() - NowTime.getTime();
var d=0; var h=0; var m=0; var s=0;
if(t>=0){
d=Math.floor(t/1000/60/60/24);
h=Math.floor(t/1000/60/60%24);
m=Math.floor(t/1000/60%60);
s=Math.floor(t/1000%60); }
document.getElementById("t_d").innerHTML = d;
document.getElementById("t_h").innerHTML = h;
document.getElementById("t_m").innerHTML = m;
document.getElementById("t_s").innerHTML = s; }
setInterval(GetRTime,0);
</script>
亲测有效
<span class="time">
<span id="t_d">00</span> 天
</span><br>
<script>
function GetRTime(){
var EndTime= new Date('2017/03/27 00:00:00');
var NowTime = new Date();
var t =EndTime.getTime() - NowTime.getTime();
var d=0; var h=0; var m=0; var s=0;
if(t>=0){
d=Math.floor(t/1000/60/60/24);
h=Math.floor(t/1000/60/60%24);
m=Math.floor(t/1000/60%60);
s=Math.floor(t/1000%60); }
document.getElementById("t_d").innerHTML = d;
document.getElementById("t_h").innerHTML = h;
document.getElementById("t_m").innerHTML = m;
document.getElementById("t_s").innerHTML = s; }
setInterval(GetRTime,0);
</script>
亲测有效
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询