我写了这段代码用jQuery来设计数字时钟,但我在某处跳过了主代码,所以无法得到结果。
$( window ).load(function() {
setTimeout(function(){
var now=new Date();
var clock= now.getHours() + ":" + now.getMinutes() + ":" +
now.getSeconds();
$("#print").text(clock);
},1000);
});
使用 setInterval
而不是 setTimeout
$(window).on("load",function() {
setInterval(function(){
var now=new Date();
var clock= now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
$("#print").text(clock);
},1000);
});