如何使用JavaScript获得开始页面加载的秒数
我已经通过剥离一些其他代码实现了这一点; 我认为这与如何使用JavaScript获得开始页面加载的秒数,javascript,clock,Javascript,Clock,我已经通过剥离一些其他代码实现了这一点; 我认为这与currentTimeString有关? 我需要第二个计时器时钟在页面加载时从0开始,而不是仅仅显示时钟时间 var d = new Date(<?php echo time() * 1000 ?>); function updateClock() { // Increment the date d.setTime(d.getTime() + 1000); var currentSeconds = d.getSeco
currentTimeString
有关?
我需要第二个计时器时钟在页面加载时从0开始,而不是仅仅显示时钟时间
var d = new Date(<?php echo time() * 1000 ?>);
function updateClock() {
// Increment the date
d.setTime(d.getTime() + 1000);
var currentSeconds = d.getSeconds();
// Generate the display string
var currentTimeString = currentSeconds + " " + "Seconds ";
// Update the time
document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}
window.onload = function() {
updateClock();
setInterval('updateClock()', 1000);
}
var d=新日期();
函数updatelock(){
//增加日期
d、 设置时间(d.getTime()+1000);
var currentSeconds=d.getSeconds();
//生成显示字符串
var currentTimeString=currentSeconds++“秒”;
//更新时间
document.getElementById(“时钟”).firstChild.nodeValue=currentTimeString;
}
window.onload=函数(){
updatelock();
setInterval('UpdateLock()',1000);
}
根据您的问题,您只想显示秒数0-59,如果是这样,请尝试每次只更新秒数,并使用firstChild.innerHTML
intead ofnodeValue
d.getSeconds(d.getSeconds() + 1);
var currentSeconds = d.getSeconds();
// Generate the display string
var currentTimeString = currentSeconds + " " + "Seconds ";
// Update the time
document.getElementById("clock").firstChild.innerHTML = currentTimeString;
这将显示系统时钟上设置的秒到分的秒数,即0-59。这就是你想做的还是不想?如果没有,请通过回答问题详细说明你想做什么。