为什么我的第二个“时间选择器"没有被填充? [英] Why is my second "timepicker" not being populated?

查看:66
本文介绍了为什么我的第二个“时间选择器"没有被填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与以下问题有关,但与之不同:如何在我的时间选择器"中添加秒?

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

我对两对文本输入控件(BeginDate/BeginTime对和EndDate/EndTime对)使用了几乎相同的jQuery代码.

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

...选择日期时,在时间"输入中输入"00:00"(我希望它是"00:00:00",但这是一种色调完全不同的马,在上面提到的问题).

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

...-尽管似乎在所有实际用途上都是相同的-但却无法在表面末末末期的"EndTime"输入文本中输入任何内容.

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

为什么会这样呢? Date val是正确的,是正确的(0,0,0,23,59,59)?除了元素的名称(EndTime代替BeginTime)之外,这两对的razor html完全相同.

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

推荐答案

请确保您同时初始化了 $.timeEntry()字段如下:

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

示例

JSFiddle示例此处.

JSFiddle Example Here.

这篇关于为什么我的第二个“时间选择器"没有被填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆