Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQueryUI日期选择器奇怪的行为_Javascript_Jquery Ui_Jquery Ui Datepicker - Fatal编程技术网

Javascript jQueryUI日期选择器奇怪的行为

Javascript jQueryUI日期选择器奇怪的行为,javascript,jquery-ui,jquery-ui-datepicker,Javascript,Jquery Ui,Jquery Ui Datepicker,在使用jqueryUI与一个简单的日期选择器一起工作时,我遇到了一个奇怪的问题。我只想显示一个两个月的日历,包括上个月和当前月份。我使用了以下代码: $(function () { $('#picker').datepicker({ numberOfMonths: 2, showCurrentAtPos: 1, dateFormat: "yy-mm-dd", onSelect: function () {

在使用jqueryUI与一个简单的日期选择器一起工作时,我遇到了一个奇怪的问题。我只想显示一个两个月的日历,包括上个月和当前月份。我使用了以下代码:

$(function () {
    $('#picker').datepicker({
        numberOfMonths: 2,
        showCurrentAtPos: 1,
        dateFormat: "yy-mm-dd",
        onSelect: function () {
            $('#out').html(this.value);
        }
    });
});

<div id="picker"></div>
<output id="out"></output>
$(函数(){
$(“#选取器”)。日期选取器({
月数:2,
showCurrentAtPos:1,
日期格式:“年月日”,
onSelect:function(){
$('#out').html(this.value);
}
});
});
它显示我想要的内容,但有一种奇怪的行为,您可以在此处查看:

当您选择一个日期时,它会跳到另一个月,在某些情况下,所选日期不再可见,即使返回的日期是正确的

如果删除行showCurrentAtPos:1,则此行为将停止,但在本例中,我将使用当前月份和下一个月份,这不是我需要的

这是虫子还是我忘了什么


顺便说一下,我使用的是jquery和jqueryUI的最新版本。目前只在Chrome上进行了测试。

如果您使用此代码更改选择功能,一切都会正常工作

  onSelect: function (dateText, inst) {
         inst.drawMonth +=1; 
        $('#out').html(this.value);
    }

下面是一个工作示例

这是一个jQuery UI datepicker错误,它发生在datepicker计算和绘制月份时,并且没有很好地使用由showCurrentAtPos定义的当前月份差异

一种可能的解决方案是将此代码块添加到票证中报告的
jquery.ui.datepicker.js
文件中:

if (inst.drawMonth == showCurrentAtPos){

drawMonth = inst.drawMonth - showCurrentAtPos;

} else{

drawMonth = inst.drawMonth;

}
或者在您的
onSelect
功能中应用补丁,如您所想:

onSelect: function (dateText, datePicker) {
    datePicker.drawMonth += $("#picker").datepicker("option", "showCurrentAtPos");
    $('#out').html(this.value);
}

Fiddle:

我找到了一个解决方案,并在datepicker子例程\u adjustDate()和\u updateDatepicker()中的两行代码中修补了jquery-ui.js:


错误修复已在,,)中向上游提交。

showCurrentAtPos仅用于在所需位置显示当前月份。这不是为了定义执行选择后的行为否,我在询问之前看到了这一点,这解决了显示日期选择器时的问题,我的问题发生在使用的日期选择器选择日期后。您可以根据所选日期重置日期选择器吗?这是一种奇怪的行为…您想要这样的行为吗?
--- jquery-ui.orig.js   2015-11-23 20:04:52.000000000 +0100
+++ jquery-ui.js    2015-11-23 17:56:37.987111191 +0100
@@ -8815,6 +8815,8 @@
        origyearshtml = inst.yearshtml = null;
        }, 0);
    }
+       // FIX BUG http://bugs.jqueryui.com/ticket/7288
+       inst.drawMonth += this._get(inst, "showCurrentAtPos");
},

// #6694 - don't focus the input if it's already focused
@@ -8940,9 +8942,14 @@
    if (this._isDisabledDatepicker(target[0])) {
        return;
    }
+       // FIX BUG http://bugs.jqueryui.com/ticket/7288
+       /*
        this._adjustInstDate(inst, offset +
        (period === "M" ? this._get(inst, "showCurrentAtPos") : 0), // undo positioning
        period);
+       */
+       this._adjustInstDate(inst, offset, period);
+
    this._updateDatepicker(inst);
},