【问题标题】:jquery datepicker validationjquery datepicker验证
【发布时间】:2012-05-17 21:12:54
【问题描述】:

如何限制用户输入未来的日期?

这是视图:

@Html.TextBoxFor(a => a.ARRIVING_DT,new { @class="date"})

$(".date").datepicker({   
    changeMonth: true,   
     changeYear: true,   
     dateFormat: 'dd/mm/yy' ,
     selectOtherMonths: true,
        showOtherMonths: true,
        showStatus: true,
        showButtonPanel: true,
        showOn: 'button',
        buttonImage: '../../Content/themes/base/images/i_cal.gif',
        buttonImageOnly: true,
        buttonText: 'Choose a Date'
          }); 

我正在尝试为此编写 valdation 属性:

    [Required(ErrorMessage = "Enter Date of Departure")]
    public object DEPARTURE_DT { get; set; } 

还有什么需要写的? Range 属性也不起作用。感谢您的任何帮助。

【问题讨论】:

标签: jquery validation datepicker


【解决方案1】:

要禁用未来日期,请添加:

maxDate: new Date,

【讨论】:

  • 感谢您的回复,但我仍然可以选择未来的日期。我试过了: maxDate: new Date maxDate: '0' maxDate: "+1D" 是否有任何特定的写入选项或必须在 maxDate 之前写入的其他必要选项的顺序?
【解决方案2】:
$('#<%= txtDate.ClientID  %>').datepicker({
                 maxDate: new Date(currentYear, currentMonth, currentDate)
             });
This will disable the future dates from getting entered. another best way for the question.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-15
    • 2014-10-08
    • 2011-12-17
    • 2015-10-29
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多