[英]How to display time/clock using dojo or dijit?
基本上,我只需要在 html 输入文本框中显示当前时间(hh:mm:ss am/pm 格式)。 并且由于这将用作时钟,因此时间应在显示时继续计数/移动。
我可以在普通的 javascript 中做到这一点,但我希望看到一个 dojo/dijit 实现。
谢谢!
这是一个您可以重复使用的示例。
您也可以使用dojox.timing.Timer自行实现。
dojo.require('dojox.timing');
t = new dojox.timing.Timer(1000);
t.onTick = function() {
//One second elapsed
var now = new Date();
//format now using dojo.date.locale.format
//update your text box with the result
}
t.onStart = function() {
//Do whatever setup is needed
}
t.start();
dojo.date.locale.format的几个例子。
看下面的代码:
var myTime = new dijit.form.TimeTextBox({
value: new Date()
constraints: {
timePattern: 'hh:mm:ss a',
},
id: "timeTb"
}, dojo.byId("timeDiv"));
var elem = document.getElementById("timeTb");
setInterval(function(){
dijit.byId("timeTb").setValue(new Date());
}, 1000);
对于极简主义方法,您可能只需通过输入控件和对 dojo.date.locale.format 的 setTimeout 调用来实现此目的。 您在这里不一定需要 DojoX/Dijit 抽象,尽管一些 dojox.timing 代码可能很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.