<script>
window.οnlοad=function(){
self.setInterval('start()',1000);
self.setInterval('end()',1000);//这个方法为设置时间间隔
}
function clock(){
self.setTimeout("alert('呵呵')",5000);//设置延迟时间
}
function start(){
var date = new Date();
var now = "当前:";
h = date.getHours();
m = date.getMinutes();
s = date.getSeconds();
if(h<10){
h="0"+h+"时";
}else{
h=h+"时"
}
if(m<10){
m="0"+m+"分";
}else{
m=m+"分"
}
if(s<10){
s="0"+s+"秒";
}else{
s=s+"秒"
}
now +=h+m+s;
document.getElementById("start").value=now;
}
function end(){
var date = new Date();
date.setHours(0,0,0,0);
var last = 86400000-(new Date() - date);
var now = "剩余:";
var h = Math.floor(last/(1000*60*60));
var m = (Math.floor(last/(1000*60)) - (h*60));
var s = Math.floor(last/(1000)) - (h*60*60) - (m*60);
if(h<10){
h="0"+h+"时";
}else{
h=h+"时"
}
if(m<10){
m="0"+m+"分";
}else{
m=m+"分"
}
if(s<10){
s="0"+s+"秒";
}else{
s=s+"秒"
}
now +=h+m+s;
document.getElementById("end").value=now;
}
window.οnlοad=function(){
self.setInterval('start()',1000);
self.setInterval('end()',1000);//这个方法为设置时间间隔
}
function clock(){
self.setTimeout("alert('呵呵')",5000);//设置延迟时间
}
function start(){
var date = new Date();
var now = "当前:";
h = date.getHours();
m = date.getMinutes();
s = date.getSeconds();
if(h<10){
h="0"+h+"时";
}else{
h=h+"时"
}
if(m<10){
m="0"+m+"分";
}else{
m=m+"分"
}
if(s<10){
s="0"+s+"秒";
}else{
s=s+"秒"
}
now +=h+m+s;
document.getElementById("start").value=now;
}
function end(){
var date = new Date();
date.setHours(0,0,0,0);
var last = 86400000-(new Date() - date);
var now = "剩余:";
var h = Math.floor(last/(1000*60*60));
var m = (Math.floor(last/(1000*60)) - (h*60));
var s = Math.floor(last/(1000)) - (h*60*60) - (m*60);
if(h<10){
h="0"+h+"时";
}else{
h=h+"时"
}
if(m<10){
m="0"+m+"分";
}else{
m=m+"分"
}
if(s<10){
s="0"+s+"秒";
}else{
s=s+"秒"
}
now +=h+m+s;
document.getElementById("end").value=now;
}
</script>
self.setInterval和self.setTimeout区别在前者会重复调用,后者只执行一次。