0

我正在为日期选择器使用 Bootstrap 插件。它工作正常。我需要两种验证。第一个是必填字段验证,第二个指定日期不接受。有人可以帮忙吗?即使我是 j 查询的初学者。提前感谢您的帮助。

jQuery代码:

$(function () {
  window.prettyPrint && prettyPrint();
  $('#ContentSection_txtFromDate, #ContentSection_txtToDate').datepicker({
     format: 'mm-dd-yyyy'
 });

aspx 代码

      <div>
            <p>
                <asp:Label ID="lblEndingTimeStamp" runat="server" Text="<span>*</span> Ending Time Stamp"
                        AssociatedControlID="ddlEndingTimeStamp"></asp:Label>
                    <asp:DropDownList ID="ddlEndingTimeStamp" runat="server">
                        <asp:ListItem Value="0">23:59:59</asp:ListItem>
                    </asp:DropDownList>
                </p>
                <p>
                    <asp:Label ID="lblToDate" runat="server" Text="<span>*</span> To Date" AssociatedControlID="txtToDate"></asp:Label><asp:TextBox
                        ID="txtToDate" runat="server" value="MM/DD/YYYY" onfocus="if(this.value == 'MM/DD/YYYY')this.value='';"
                        onblur="if(this.value =='')this.value='MM/DD/YYYY';"></asp:TextBox></p>

            </div>
4

1 回答 1

0

假设您正在执行某种类型的表单提交,假设trip-picker<form>id,以下将捕获未填充的字段和无效的日期组合:

$('#trip-picker').submit(function() {
  var fromDate = $('#ContentSection_txtFromDate').val(),
      toDate = $('#ContentSection_txtFromDate').val();

  if (!fromDate || !toDate) {
    alert("both dates required!");
    return false;
  } else if (Date.parse(fromDate) > Date.parse(toDate)) {
    alert("departure date must precede return date!");
    return false;
  }

});
于 2012-07-10T17:28:01.473 回答