Why is my second “timepicker” not being populated?

╄→гoц情女王★ 提交于 2019-12-12 00:12:57

问题


This question is related to, but different from, this one: How can I add Seconds to my "timepicker"?

I'm using virtually identical jQuery code for two pairs of text input controls (a BeginDate/BeginTime pair, and a EndDate/EndTime pair).

The first pair works fine with this code:

var beginDatepickerOpts = {
  changeMonth: true,
  changeYear: true,
  showWeek: true,
  onClose: function() {
                    if (($("#BeginTime").val()).length == 0) {
                        $("#BeginTime").timeEntry("setTime", new Date(0, 0, 0, 0, 0, 0));
                    }
                    $("#BeginTime").focus();
                }
        }

$("#BeginDate").datepicker(beginDatepickerOpts);

...on selecting a date, "00:00" is entered into the "time" input (I want it to be "00:00:00", but that's an equine of a decidedly different hue, discussed in the question referenced above).

However, this code for the second pair of inputs:

   var endDatepickerOpts = {
     changeMonth: true,
     changeYear: true,
     showWeek: true,
     onClose: function() {
                if (($("#EndTime").val()).length == 0) {
                    $("#EndTime").timeEntry("setTime", new Date(0, 0, 0, 23, 59, 59));
                }
                $("#EndTime").focus();
            }
    }

    $("#EndDate").datepicker(endDatepickerOpts);

... -- although it seems to be for all practical purposes indentical -- fails to enter anything into the superficially eschatological "EndTime" input text.

Why would that be the case? The Date val is correct, correct (0, 0, 0, 23, 59, 59)? The razor html for the two pairs is identical except for the names of the elements (EndTime instead of BeginTime).


回答1:


Make sure that you initialize both occurrences of the $.timeEntry() fields like so:

// Start Date / Time
var beginDatepickerOpts = {
    ...
}
$('#BeginTime').timeEntry(); // Initialize the BeginTime TimeEntry Field
$("#BeginDate").datepicker(beginDatepickerOpts);

// End Date / Time
var endDatepickerOpts = {
    ...
}
$('#EndTime').timeEntry(); // Initialize the EndTime TimeEntry Field
$("#EndDate").datepicker(endDatepickerOpts);

EXAMPLE

JSFiddle Example Here.



来源:https://stackoverflow.com/questions/16991020/why-is-my-second-timepicker-not-being-populated

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