javascript jquery ui datepicker 两个日期之间的范围

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13530800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:04:30  来源:igfitidea点击:

jquery ui datepicker range between two dates

javascriptjquery

提问by L.S

Can you please show me how to enable range in jquery ui datepicker, I want to determine range in the format: from 2012-12-10 to 2012-12-20 etc (yy-mm-dd, already specified). All other dates should not be available.

你能告诉我如何在 jquery ui datepicker 中启用范围吗,我想确定以下格式的范围:从 2012-12-10 到 2012-12-20 等(yy-mm-dd,已经指定)。所有其他日期都不应该可用。

Appreciate the help I can get, cheers!

感谢我能得到的帮助,干杯!

回答by Franky

try this:

试试这个:

function setInterval(){
$(function() {
    $( "#startDate" ).datepicker({
        defaultDate: "+1w",
        onSelect: function( selectedDate ) {
            $( "#endDate" ).datepicker( "option", "minDate", selectedDate );
        }
    });
    $( "#endDate" ).datepicker({
        defaultDate: "+1w",
        onSelect: function( selectedDate ) {
            $( "#startDate" ).datepicker( "option", "maxDate", selectedDate );
        }
    });
});
}

where

在哪里

startDate  
endDate

are the two input fields of datepicker

是 datepicker 的两个输入字段

回答by DarkAjax

Try something like:

尝试类似:

jQuery("#date").datepicker({
    beforeShow: function() {
        return {
            dateFormat: 'yy-mm-dd',
            minDate: '2012-12-10',
            maxDate: '2012-12-20',
        }
    }
});

回答by talegna

The previous answer is correct, example:

前面的答案是正确的,例如:

$(function() {
    $( "#datepicker" ).datepicker({ minDate: new Date(2012, 12, 10), maxDate: new Date(2012, 12, 20) });
});

I just wanted to add the following links which you might find useful:

我只想添加以下您可能会觉得有用的链接:

http://jqueryui.com/datepicker/#min-max

http://jqueryui.com/datepicker/#min-max

http://api.jqueryui.com/datepicker/

http://api.jqueryui.com/datepicker/

回答by Diego

Use maxDateand minDateoptions when creating.

创建时的使用maxDateminDate选项。

Link

关联

Code:

代码:

$( "#datepicker" ).datepicker({ minDate: value1, maxDate: value2 });