gpt4 book ai didi

javascript - 在 Jquery 中附加后渲染实时时钟

转载 作者:行者123 更新时间:2023-12-02 17:14:25 24 4
gpt4 key购买 nike

我尝试了很多方法来使实时时钟(带秒)出现在渲染表中,但它无法正常工作。时钟保持静止,不显示一秒一秒。我正在执行以下操作:

function myTable(){
var table = $('<table></table>');
table.append($('<tr>')
.append($('<td>')
.addClass('col2 data')
.attr('rowspan', '2')
.append($('<span>')
.attr('id', 'date_time')
)
)
)
$("#myDiv").html(table)
}

liveClock();


var liveClock = function () {

date = new Date;
//some logic here to generate the data I need the result above ( no problems here )

result = '' + d + '/' + month + '/' + year + ' ' + h + ':' + m + ':' + s;

var setDateTime = function() {
$("#date_time").html(result);
return false;
};
var everySec = setInterval(setDateTime, 1000);
}

最佳答案

您的问题是您从未更新结果,因此每次您的代码触发SetDateTime时,它都会在表中呈现相同的日期。移动这些行:

date = new Date;
//some logic here to generate the data I need the result above ( no problems here )

result = '' + d + '/' + month + '/' + year + ' ' + h + ':' + m + ':' + s;

进入您的setDateTime函数。

关于javascript - 在 Jquery 中附加后渲染实时时钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24561766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com