2011-12-30 81 views
0

我想在使用兩個datepicker「effectiveDate」和「termDate」的窗體上使用jquery驗證。 EffectiveDate不得早於TermDate。日期選擇工作,但沒有任何錯誤顯示時,我違反了驗證。jquery驗證現在工作

<script language="javascript" type="text/javascript"> 
    jQuery(document).ready(function() { 
     $("form").validate(); 
     var term = $("#TermDate").val(); 
     $("#EffectiveDate").datepicker({ 
      minDate: term 
     }); 
    }); 
</script> 
+0

你如何配置jQuery驗證?我沒有看到任何規定。 – epignosisx 2011-12-30 19:47:21

+0

我想不是。我的印象是它會理解minDate。從我在http://keith-wood.name/uiDatepickerValidation.html看到的 – 2011-12-30 19:52:41

回答

1

您需要申請在this article解釋的驗證規則(dpDate):

jQuery(document).ready(function() { 
    $("form").validate({ 
     rules: { 
      // EffectiveDate is the name of the input, not the id 
      // so make sure that the input is defined like this: 
      // <input type="text" id="EffectiveDate" name="EffectiveDate" /> 
      EffectiveDate: { 
       required: true, 
       dpDate: true 
      } 
     } 
    }); 

    var term = $("#TermDate").val(); 
    $("#EffectiveDate").datepicker({ 
     minDate: term 
    }); 
}); 

對於此規則生效,您必須將jquery.ui.datepicker.validation.js擴展添加到您的網頁。