【发布时间】:2017-07-14 08:47:19
【问题描述】:
请有人帮助我...
所以我得到了这个 JS 函数,它可以让我显示时间:
function getCurrentTime() {
var CurrentTime = "";
try {
var CurrentDate = new Date();
var CurrentHours = CurrentDate.getHours();
var CurrentMinutes = CurrentDate.getMinutes();
var CurrentSeconds = CurrentDate.getSeconds();
if (CurrentMinutes < 10) { CurrentMinutes = "0" + CurrentMinutes; }
if (CurrentSeconds < 10) { CurrentSeconds = "0" + CurrentSeconds; }
if (CurrentHours < 10) { CurrentHours = "0" + CurrentHours; }
CurrentTime = "" + CurrentHours + ":" + CurrentMinutes + ":" + CurrentSeconds + "";
}
catch (ex) {
}
return CurrentTime;
}
然后我像这样通过 jQuery 日期选择器返回它:
$('.class').datepicker({
autoclose: true,
format: "dd.mm.yyyy" + " " + getCurrentTime(),
}
我遇到的问题是,在我选择当前日期的框中,我无法修改时间,即使我在选择日期后更改数字我总是得到当前时间,但我希望我可以有我在该领域介绍的任何时间。
你能帮我解决这个问题吗?
【问题讨论】:
-
设置日期你应该使用 setDate $( ".selector" ).datepicker( "setDate", "10/12/2012" ); api.jqueryui.com/datepicker/#method-setDate
-
你为什么不把时间存储在一个全局变量中,然后再使用它?!
-
请详细说明一下?
标签: javascript jquery time datepicker