【问题标题】:jQueryUI datepicker('setDate') removes timejQueryUI datepicker('setDate') 删除时间
【发布时间】:2010-08-16 06:23:34
【问题描述】:

这是 jQuery UI 中的错误吗?当我调用.datepicker('setDate', date); 并且date 是一个带时间的日期对象时,日期选择器将date 的时间设置为0:00?

如果我克隆变量..

var datewithtime = new Date();
var lTmpDate = datewithtime;
$('#Modal_KalendarTermin #DP_DatumVon').datepicker("setDate", lTmpDate);

.. datewithtime 是一样的(没有时间 - 只有时间 = 0:00 的日期)。

我在jquery-ui.js -> 搜索“_setDate: function”中找到了第三个参数“noChange”。为了什么?

摘自 jquery-ui.js

/* Set the date(s) directly. */
_setDate: function(inst, date, noChange) {
    var clear = !(date);
    var origMonth = inst.selectedMonth;
    var origYear = inst.selectedYear;
    date = this._restrictMinMax(inst, this._determineDate(inst, date, new Date()));
    inst.selectedDay = inst.currentDay = date.getDate();
    inst.drawMonth = inst.selectedMonth = inst.currentMonth = date.getMonth();
    inst.drawYear = inst.selectedYear = inst.currentYear = date.getFullYear();
    if ((origMonth != inst.selectedMonth || origYear != inst.selectedYear) && !noChange)
        this._notifyChange(inst);
    this._adjustInstDate(inst);
    if (inst.input) {
        inst.input.val(clear ? '' : this._formatDate(inst));
    }
},

感谢您的回答,抱歉我的英语不好!

【问题讨论】:

    标签: jquery jquery-ui datepicker


    【解决方案1】:

    jQuery UI 日期选择器只处理日期。从链接的代码可以看出,传递给setDate 的日期仅用于设置currentDaycurrentMonthcurrentYear 的值。根据设计,所有其他日期信息都将被删除。

    noChange 参数是一个标志,可能只在内部使用,用于确定值更改时是否调用notifyChange

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-19
      • 2010-12-29
      • 1970-01-01
      • 2012-02-25
      • 1970-01-01
      • 2014-12-12
      相关资源
      最近更新 更多