JS 倒计时实现代码(时、分,秒)

JavaScript015

JS 倒计时实现代码(时、分,秒),第1张

JS实现倒计时(时、分,秒)

var

interval

=

1000

function

ShowCountDown(year,month,day,divname)

{

var

now

=

new

Date()

var

endDate

=

new

Date(year,

month-1,

day)

var

leftTime=endDate.getTime()-now.getTime()

var

leftsecond

=

parseInt(leftTime/1000)

//var

day1=parseInt(leftsecond/(24*60*60*6))

var

day1=Math.floor(leftsecond/(60*60*24))

var

hour=Math.floor((leftsecond-day1*24*60*60)/3600)

var

minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60)

var

second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60)

var

cc

=

document.getElementById(divname)

cc.innerHTML

=

"脚本之家提示距离"+year+"年"+month+"月"+day+"日还有:"+day1+"天"+hour+"小时"+minute+"分"+second+"秒"

}

window.setInterval(function(){ShowCountDown(2010,4,20,'divdown1')},

interval)

[Ctrl+A

全选

注:如需引入外部Js需刷新才能执行]

倒计时可以用js的setTimeout来控制

http://www.tocus.com.cn/?send=article_show&id=34&class=2

可以循环计时,而对于页面刷新,我们可以屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键来达到效果

<script>

//屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键

function document.oncontextmenu(){event.returnValue=false}//屏蔽鼠标右键

function window.onhelp(){return false} //屏蔽F1帮助

function document.onkeydown(){

if((window.event.altKey)&&((window.event.keyCode==37)||(window.event.keyCode==39))){

//屏蔽Alt+方向键←

//屏蔽Alt+方向键→

event.returnValue=false

}

if((event.keyCode==8)||(event.keyCode==116)||(event.ctrlKey &&event.keyCode==82)){

//屏蔽退格删除键

//屏蔽F5刷新键

//Ctrl+R

event.keyCode=0

event.returnValue=false

}

if(event.keyCode==122){event.keyCode=0event.returnValue=false}//屏蔽F11

if(event.ctrlKey &&event.keyCode==78)event.returnValue=false //屏蔽Ctrl+n

if(event.shiftKey &&event.keyCode==121)event.returnValue=false //屏蔽shift+F10

if(window.event.srcElement.tagName=="A" &&window.event.shiftKey)

window.event.returnValue=false //屏蔽shift加鼠标左键新开一网页

if((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4

window.showModelessDialog("about:blank","","dialogWidth:1pxdialogheight:1px")

return false

}

}

</script>