如何在“时间选择器"中添加“秒"? [英] How can I add Seconds to my "timepicker"?
问题描述
我以这种方式使用jQuery-UI datepicker:
I'm using the jQuery-UI datepicker in this way:
var datepickerOpts = {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
showWeek: true,
onClose: function(dateText, inst) {
if (($("#BeginTime").val()).length == 0) {
$("#BeginTime").timeEntry("setTime", new Date(0, 0, 0, 0, 0, 0));
}
$("#BeginTime").focus();
}
}
$("#BeginDate").datepicker(datepickerOpts);
相关的[cs] html是:
The related [cs]html is:
<tr id="trBeginDate">
<td>
</td>
<td>
@Html.LabelFor(m => m.BeginDate)
</td>
<td style="padding-right: 20px;">
@Html.TextBoxFor(m => m.BeginDate, new {alt = "date-us", style = "width: 109px;"})
</td>
<td>
@Html.LabelFor(m => m.BeginTime)
</td>
<td style="padding-right: 20px;">
@Html.TextBoxFor(m => m.BeginTime, new {style = "width: 109px;"})
</td>
</tr>
我希望在BeginTime文本框中显示为默认值的是"00:00:00",而不仅仅是得到的"00:00":
What I want to show as a default value in the BeginTime textbox is "00:00:00", not just "00:00" as I get:
实际上,对于默认的午夜开始时间,"00:00"可能还可以,但是我需要默认的结束时间为"23:59:59",而不是现在的时间("23:59"),因为这样一来,实际上一分钟可能会丢失(从"23:59:01"到"23:59:59").因此,"00:00"应为"00:00:00",以与"23:59:59"具有一致的格式.)
Actually, "00:00" is probably okay for the default begin time of midnight, but I need the default end time to be "23:59:59" not what it is now ("23:59") because that way practically an entire minute is potentially lost (from "23:59:01" to "23:59:59"). And so, "00:00" should be "00:00:00" to have a consistent format with "23:59:59").
无论如何,我尝试了此操作,但它根本不起作用(BeginTime文本框未添加任何内容):
Anyway, I tried this, but it doesn't work at all (nothing is added to the BeginTime textbox):
. . .
onClose: function(dateText, inst) {
if (($("#BeginTime").val()).length == 0) {
$("#BeginTime").text("00:00:00");
. . .
也没有这样做:
. . .
onClose: function(dateText, inst) {
if (($("#BeginTime").val()).length == 0) {
$("#BeginTime").text.val("00:00:00");
. . .
那么如何将BeginTime值设置为"00:00:00"?
So how can I set the BeginTime value to "00:00:00"?
推荐答案
看看$ .timeEntry()其他问题,您将如何设置秒数还有24小时制:
Take a look at the $.timeEntry() documentation, under the 'formats' tab is how to set different default formats. Based on your other question here is how you would set seconds and a 24 hour clock:
// Start Date / Time
var beginDatepickerOpts = {
...
}
$('#BeginTime').timeEntry({
showSeconds: true,
show24Hours: true
});
$("#BeginDate").datepicker(beginDatepickerOpts);
// End Date / Time
var endDatepickerOpts = {
...
}
$('#EndTime').timeEntry({
showSeconds: true,
show24Hours: true
});
$("#EndDate").datepicker(endDatepickerOpts);
示例
JSFiddle示例此处.
JSFiddle Example here.
这篇关于如何在“时间选择器"中添加“秒"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!