本文目录一览:
- 1、JS倒计时页面代码(要求读取服务器时间)
- 2、js写在线考试倒计时器
- 3、求倒计时代码,js,php都行。格式: 距高考还有 145 天
- 4、如何实现js优惠券倒计时
- 5、JS/JQ实现倒计时
- 6、帮忙改一个js倒计时代码
JS倒计时页面代码(要求读取服务器时间)
script language="JavaScript"
function setTab(name,cursel,n){
for(i=1;i=n;i++){
var menu=document.getElementById(name+i);
var con=document.getElementById("con_"+name+"_"+i);
menu.className=i==cursel?"hover":"";
con.style.display=i==cursel?"block":"none";
}
}var DifferenceHour = -1
var DifferenceMinute = -1
var DifferenceSecond = -1
var Tday = new Date("Feb 14, 2010 00:00:00") //**倒计时时间点-注意格式
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondms = 60 * 1000
var microsecond = 1000function left(mainStr,lngLen) {
if (lngLen0) {return mainStr.substring(0,lngLen)}
else{return null}
}
function right(mainStr,lngLen) { if (mainStr.length-lngLen=0 mainStr.length=0 mainStr.length-lngLen=mainStr.length) {
return mainStr.substring(mainStr.length-lngLen,mainStr.length)}
else{return null}
}
function mid(mainStr,starnum,endnum){
if (mainStr.length=0){
return mainStr.substr(starnum,endnum)
}else{return null} }function clock()
{
var time = new Date()
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var timevalue = ""+((hour 12) ? hour-12:hour)
timevalue +=((minute 10) ? ":0":":")+minute
timevalue +=((second 10) ? ":0":":")+second
timevalue +=((hour 12 ) ? " PM":" AM")var convertHour = DifferenceHour
var convertMinute = DifferenceMinute
var convertSecond = DifferenceSecond
var Diffms = Tday.getTime() - time.getTime()
DifferenceHour = Math.floor(Diffms / daysms)
Diffms -= DifferenceHour * daysms
DifferenceMinute = Math.floor(Diffms / hoursms)
Diffms -= DifferenceMinute * hoursms
DifferenceSecond = Math.floor(Diffms / Secondms)
Diffms -= DifferenceSecond * Secondms
var dSecs = Math.floor(Diffms / microsecond)var dd=document.getElementById("dd");
var hh=document.getElementById("hh");
var mm=document.getElementById("mm");
var ss=document.getElementById("ss");ddstr = DifferenceHour.toString();
hhstr = DifferenceMinute.toString();
mmstr = DifferenceSecond.toString();
ssstr = dSecs.toString();if (Tday.getTime() time.getTime()){
if (ddstr.length2){
ddstrs = "span class='num0'/spanspan class='num"+ddstr.substr(0,1)+"'/span";
}else{
ddstrs = "span class='num"+ddstr.substr(0,1)+"'/spanspan class='num"+ddstr.substr(1,2)+"'/span";
}if (hhstr.length2){
hhstrs = "span class='num0'/spanspan class='num"+hhstr.substr(0,1)+"'/span";
}else{
hhstrs = "span class='num"+hhstr.substr(0,1)+"'/spanspan class='num"+hhstr.substr(1,2)+"'/span";
}if (mmstr.length2){
mmstrs = "span class='num0'/spanspan class='num"+mmstr.substr(0,1)+"'/span";
}else{
mmstrs = "span class='num"+mmstr.substr(0,1)+"'/spanspan class='num"+mmstr.substr(1,2)+"'/span";
}if (ssstr.length2){
ssstrs = "span class='num0'/spanspan class='num"+mmstr.substr(0,1)+"'/span";
}else{
ssstrs = "span class='num"+ssstr.substr(0,1)+"'/spanspan class='num"+ssstr.substr(1,2)+"'/span";
}
}else{
ddstrs="span class='num0'/spanspan class='num0'/span"
hhstrs="span class='num0'/spanspan class='num0'/span"
mmstrs="span class='num0'/spanspan class='num0'/span"
ssstrs="span class='num0'/spanspan class='num0'/span"
}if(convertHour != DifferenceHour) dd.innerHTML=ddstrs;
if(convertMinute != DifferenceMinute) hh.innerHTML=hhstrs;
if(convertSecond != DifferenceSecond) mm.innerHTML=mmstrs;
ss.innerHTML=ssstrs;
setTimeout("clock()",1000)}/script 上面的是JS部分的。 下面是HTML部分的。div class="mains"
div class="djs"
div id="dd"/div
div id="tsfm"天/div
div id="hh"/div
div id="tsfm"时/div
div id="mm"/div
div id="tsfm"分/div
div id="ss"/div
div id="tsfm"秒/div
/div 我上面的JS部分的数字全部是用的图片格式显示倒计时数字的哈,你也可以自己改成数字。 好了,上面的代码全部是我之前给客户写的一个春节倒计时贺卡的程序页面,纯原创,并且一直在用,所以是没有任何问题的,你自己应该懂一些技术吧,所以上面的代码你应该看的懂,很简单的。 就不要再追问了,自己多下下功夫研究下,因为最近比较忙,不见得有时间回复,见谅。记得给我分哈,要升级这个号的级别,以后好推广用,谢谢了。
js写在线考试倒计时器
一个html页面,一个按钮,onclick事件
location.href="";
跳转到另一个html页面
另一个页面里
onload = function (){
// 开始计时
}
求倒计时代码,js,php都行。格式: 距高考还有 145 天
!DOCTYPE html
html
head
meta charset="utf-8"
script type="text/javascript"
window.onload = function(){
function DistenceOfDate(year,month,day,hour,minute,seconds) {
var date = new Date();
var dateMill = date.getTime();
var targetDate = new Date(year,(month -1),day,hour,minute,seconds);
var targetMill = targetDate.getTime();
var perDay = 3600 * 1000 * 24;
var perHour = 3600*1000;
var perMin = 60000;
var perSec = 1000;
var offset = targetMill - dateMill ;
var tmp = offset % perDay;
var days = parseInt(offset / perDay);
log(days);
var offsetHour = tmp % perHour ;
var hours = parseInt(tmp/ perHour);
log(hours);
var offsetMin = offsetHour % perMin ;
var min = parseInt(offsetHour /perMin );
log(min);
var offsetSec = offsetMin % perSec ;
var secs = parseInt(offsetMin /perSec );
log(secs);
log(offsetSec);
function log (str){
console.log(str);
}
return{
day:days,
h:hours,
m:min,
s:secs,
ms:offsetSec
}
}
setInterval(function(){
var obj = DistenceOfDate(2014,11,30,00,00,00);
document.querySelector("#msg.msg").innerHTML ="距离 2014年11月30日0时0分0秒还有:/br"+obj.day+" 天 "+obj.h+" 小时 "+obj.m+" 分钟"+
obj.s+"秒 ";
},1000);
}
/script
style type="text/css"
.msg{
width: 100%;
height: 40px;
background: #1990d5;
color:#FBBDEE;
text-align: center;
}
/style
/head
body
div id="msg" class="msg"/div
/body
/html
刚写的热乎的。程序精确到秒啦
如何实现js优惠券倒计时
!doctype html
html
head
meta charset="utf-8"
titlejquery版的网页倒计时效果/title
style type="text/css"
/style
script src=""/script
script type="text/javascript"
var intDiff = parseInt(86400); //倒计时总秒数量(1天=24*60*60=86400)
function timer(intDiff) {
window.setInterval(function() {
var day = 0,
hour = 0,
minute = 0,
second = 0; //时间默认值
if(intDiff 0) {
day = Math.floor(intDiff / (60 * 60 * 24));
hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
}
if(minute = 9) minute = '0' + minute;
if(second = 9) second = '0' + second;
$('#day_show').html(day + "天");
$('#hour_show').html('s id="h"/s' + hour + '时');
$('#minute_show').html('s/s' + minute + '分');
$('#second_show').html('s/s' + second + '秒');
intDiff--;
}, 1000);
}
$(function() {
timer(intDiff);
});
/script
/head
body
div class="time-item"
span id="day_show"0天/span
span id="hour_show"0时/span
span id="minute_show"0分/span
span id="second_show"0秒/span
/div
/body
/html
form
JS/JQ实现倒计时
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
html
head
titlejs倒计时代码 - k686绿色软件 - ;/title
meta name="Generator" content="EditPlus"
meta name="Author" content="k686绿色软件 "
meta name="Keywords" content="绿色软件"
meta name="Description" content="绿色软件" /head body
script
function countDown( maxtime,fn )
{
var timer = setInterval(function()
{
if(maxtime=0){
d=parseInt(maxtime/3600/24);
h=parseInt((maxtime/3600)%24);
minutes=parseInt((maxtime/60)%60);
seconds=parseInt(maxtime%60);
//minutes = Math.floor(maxtime/60);
//seconds = Math.floor(maxtime%60);
msg = "距离结束还有"+d+"天"+h+"小时"+minutes+"分"+seconds+"秒";
fn( msg );
if(maxtime == 5*60) alert('注意,还有5分钟!');
--maxtime;
}
else{
clearInterval( timer );
fn("时间到,结束!");
}
}, 1000);
}
/scriptdiv id="timer1" style="color:red"/div
script
countDown( 6000,function( msg ) //6000服务器时间差 单位为妙
{
document.getElementById('timer1').innerHTML = msg;
});
/scriptdiv id="timer2" style="color:red"/div
script
countDown( 6000,function( msg )
{
document.getElementById('timer2').innerHTML = msg;
});
/scriptdiv id="timer3" style="color:red"/div script
countDown( 600000,function( msg )
{
document.getElementById('timer2').innerHTML = msg;
});
countDown( 30,function( msg )
{
document.getElementById('timer3').innerHTML = msg;
})
/script
/body
/html
帮忙改一个js倒计时代码
(function(timeleft) {
var minutes = 0,
seconds = 0,
caller = arguments.callee,
timer;
if(--timeleft = 0) {
minutes = Math.floor(timeleft / 60);
seconds = Math.floor(timeleft % 60);
document.all["timer"].innerHTML = "距离结束还有" + minutes + "分" + seconds + "秒";
if (timeleft == 5 * 60) {
alert('注意,还有5分钟!');
}
setTimeout(function() {
caller(timeleft);
}, 1000);
} else {
alert("时间到,结束!");
}
}(3600));