【问题标题】:Jquery Calendar Disable Past Month Issue [duplicate]Jquery日历禁用过去一个月的问题[重复]
【发布时间】:2013-05-13 09:27:00
【问题描述】:

我有一个 html 格式的 Jquery 日历。它显示从和到日期。以下是我的代码:

html头部代码:

<link rel="stylesheet" href="jquery/jquery.ui.all.css">
<script src="jquery/jquery-1.9.1.js"></script>
<script src="jquery/jquery.ui.core.js"></script>
<script src="jquery/jquery.ui.widget.js"></script>
<script src="jquery/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" href="../demos.css">


<script>

$(function() {
    $( "#from" ).datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
        onClose: function( selectedDate ) {
            $( "#to" ).datepicker( "option", "minDate", selectedDate );


        }
    });
    $( "#to" ).datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
        onClose: function( selectedDate ) {
            $( "#from" ).datepicker( "option", "maxDate", selectedDate );
        }
    });
});
</script>

html正文代码:

<label for="from">From</label>
<input type="text" id="from" name="from" class="tr"/>
<label for="to">to</label>
<input type="text" id="to" name="to" class="tr"/>

嗯,它工作正常。但是是否可以禁用过去一个月的归档名称 from ?我只是希望用户不能选择上个月到 from 字段。

日历现在的工作方式: 如果用户选择从日期,即 18-05-2013 则 To date 从 18-05-2013 开始,如果它的 20-08-2013 则 to date 从 20-08-2013 开始。

【问题讨论】:

标签: jquery html


【解决方案1】:

你必须使用 mindate 参数

$( "#from" ).datepicker({
    defaultDate: "+1w",
    changeMonth: true,
    numberOfMonths: 1,
    minDate: new Date(), // <-------- this will disable all dates prior to the date passed there.
    onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );


    }
});

【讨论】:

  • 非常感谢。 @fmsf。它正在工作..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-11
相关资源
最近更新 更多