How can I add Seconds to my “timepicker”?

这一生的挚爱 提交于 2019-12-12 00:27:30

问题


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);

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>

What I want to show as a default value in the BeginTime textbox is "00:00:00", not just "00:00" as I get:

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").

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");
. . .

nor did this:

. . .
onClose: function(dateText, inst) {
                        if (($("#BeginTime").val()).length == 0) {
                            $("#BeginTime").text.val("00:00:00");
. . .

So how can I set the BeginTime value to "00:00:00"?


回答1:


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);

EXAMPLE

JSFiddle Example here.




回答2:


Just go to the link and you will get the required stuff. http://www.avisbra.it/wp-content/plugins/lbwp_book/js/jquery/plugin/timepicker/



来源:https://stackoverflow.com/questions/16989566/how-can-i-add-seconds-to-my-timepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!