Jquery UI日期和日期到字段验证

时间:2014-10-14 11:41:39

标签: javascript jquery jquery-ui jquery-plugins

有人可以帮我解决这个问题,我在从jquery验证datepicker时遇到问题,我需要验证两个日期来自和来,事情是从日期被禁用,因为minDate选项似乎不起作用。 。无论如何,我可以检查To-Date字段的有效性,该字段不会小于From-Date。感谢那些会帮助我的人。

3 个答案:

答案 0 :(得分:0)

    function CheckDate()
    {
      var StartDate= document.getElementById('txtStartDate').value;
      var EndDate= document.getElementById('txtEndDate').value;
      var eDate = new Date(EndDate);
      var sDate = new Date(StartDate);
if(EndDate=="")
        {
        alert("Please Enter EndDate");
        }
       else
      {     
    if(StartDate!= '' && StartDate!= '' && sDate> eDate)
      {
      alert("End Date is greater than or equal to the Start Date.");
      return false;
      }
        }
  }

答案 1 :(得分:0)

我已经弄明白了,我已经将.datepicker方法放在ajax的完整函数之后,因为我正在填充ajax请求中的数据。所以不要将.datepicker放在.ready函数上。

以下是我创建的示例代码:

function GetInfo() {
    $.ajax({
        type : "POST",
        url : "test",
        data : "{}",
        contentType : "application/x-www-form-urlencoded",
        dataType : "json",
        success : function(response) {
 },
complete : function(e) {
$("#id-of-the-DOM-end-element")
            .datepicker(
                    {
                        minDate : new Date($("#id-of-the-DOM-start-element").val()),
                        'http://jqueryui.com/resources/demos/datepicker/images/calendar.gif'
                    });
});

答案 2 :(得分:0)

假设日期文本字段中有一些值被禁用(因为问题没有被正确引用)。

虽然从日期开始禁用文本框,但您可以使用js / jQuery(例如$("#fromID").val();

)获取文本框的值

使用此脚本限制toDate文本框的最小日期:

<script>
  var min=$("#fromID").val();
  $(function() {
    $( "#toID" ).datepicker({ minDate: min });
  });
  </script>