【问题标题】:how to validate date in javascript which allows only same date for both from and to date time picker如何在javascript中验证日期,它只允许从日期时间选择器和到日期时间选择器相同的日期
【发布时间】:2014-04-17 09:30:41
【问题描述】:

我有一个表格,其中我有 2 个日期时间选择器,从 date 和 to date 开始,我的要求是,如果选择的 from date 是 17-4-2014,那么 to date 也必须在同一日期。它不应该允许 18 或任何其他日期。它还应该验证 time 的 time 不能小于 from time 。请帮助我使用 javascript 解决此问题

【问题讨论】:

标签: javascript jquery date


【解决方案1】:

试试这样的

$(function(){
        $("#datepicker1").datepicker(
                {dateFormat: "dd-M-yy",
                        changeMonth: true,
                        changeYear: true,
                minDate: '-60Y', maxDate: '+0Y',
                yearRange: '-60:+20',
                showOn: "button",
                buttonImage: '/cpf/images/datepicker.gif',
                buttonImageOnly: true
                }
                );
    });
         $(function(){
        $("#datepicker2").datepicker(
                {dateFormat: "dd-M-yy",
                        changeMonth: true,
                        changeYear: true,
                minDate: '-60Y', maxDate: '+0Y',
                yearRange: '-60:+20',
                showOn: "button",
                buttonImage: '/cpf/images/datepicker.gif',
                buttonImageOnly: true
                }
                );
    });

<TD align="right" width="10%"><strong>Service Date From</strong></TD>
        <TD width="16%"><input id="datepicker1" name="check_in_from" class="input_style4" type="text" readonly value="{$form.check_in_from|date_format:" %d-%b-%Y"}" style="width: 160px;"> <img src="images/clear.gif" alt="clear" title="clear" onclick="clear1('datepicker1')"></td>
        <TD align="right" width="11%"><strong>Service Date To</strong></TD>
        <TD width="16%"><input id="datepicker2" name="check_in_to" class="input_style4" type="text" readonly value="{$form.check_in_to|date_format:" %d-%b-%Y"}" style="width: 160px;"> <img src="images/clear.gif" alt="clear" title="clear" onclick="clear1('datepicker2')"></TD>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-14
  • 1970-01-01
相关资源
最近更新 更多