简体   繁体   English

如何在jQuery UI Datepicker上禁用datepicker的关闭

[英]How to disable closing of datepicker on jQuery UI Datepicker

When i open a datepicker like that: 当我打开这样的日期选择器时:

$("#checkindate,#checkoutdate").datepicker({
    onClose: {
       //I'd like to disable the closing
    }
);

I'd like to prevent the closing of the datepicker dialog depending on a condition. 我想根据条件阻止关闭datepicker对话框。 The ideal would be that 'return false' would stop this event. 理想的是'return false'会停止此事件。

I tried modifying the source code and there is no trivial solution. 我尝试修改源代码,没有简单的解决方案。

What I want to do is to be able to select the checkout date without reopening another dialog. 我想要做的是能够选择结帐日期而无需重新打开另一个对话框。

Any idea? 任何想法?

I don't think it's possible to pick multiple dates from one datepicker. 我不认为可以从一个日期选择器中选择多个日期。 You probably will need to do something like their date range demo: http://jqueryui.com/demos/datepicker/#date-range 您可能需要执行类似日期范围演示的操作: http//jqueryui.com/demos/datepicker/#date-range

$('#datepicker').blur(function(){
$(this).datepicker('show')
})

open up http://jqueryui.com/demos/datepicker/ and copy the code on the javascript console and see what happens 打开http://jqueryui.com/demos/datepicker/并在javascript控制台上复制代码,看看会发生什么

var selectTask = function(selectedDate, calendar) { // pretends to remain open                         
                     setTimeout(function() {
                        $(selector).datepicker('show'); // don't go away ...
                     }, 0);
                 };
// datepicker instance
$(selector).datepicker({ onSelect:selectTask, duration:0 });

It's an illusion of prevent closing; 这是一种阻止关闭的错觉; might reach the goal. 可能达到目标。

After spending around a day finally got it, 花了大约一天后终于搞定了,

$( "#selector" ).datepicker({
        onSelect: function ( dateText, inst ) {
             this._updateDatepicker(inst);
         }
});

For all code, click here . 对于所有代码, 请单击此处

In this question: jQuery UI Datepicker - Multiple Date Selections the accepted answer explains how to implement the multiple date selection in one datepicker. 在这个问题中: jQuery UI Datepicker - 多个日期选择接受的答案解释了如何在一个日期选择器中实现多个日期选择。

To prevent the datepicker closing after the selection of a date, you can put this in the onClose option: 要在选择日期后阻止日期选择器关闭,可以将其放在onClose选项中:

$(this).data('datepicker').inline = false;

And add this in onSelect option: 并在onSelect选项中添加:

$(this).data('datepicker').inline = true;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM