Jquery datepicker验证

时间:2014-05-09 10:26:02

标签: jquery jquery-ui jquery-ui-datepicker

我有两个带有jquery datepicker的文本字段。

如果所选日期大于今天的日期(当前日期),则在第一个字段中

。它应该向用户提示消息。

在第二个字段中,用户必须选择比当前日期大至少6个月的日期。否则,它应该提示用户提醒或其他什么。我尽我所能但却无法做到这一点。请帮帮我。

    $( "#issueDate" ).datepicker({
         changeMonth: true,
          changeYear: true,
          showOn: "button",
          buttonImage: "images/date-picker.png",
          buttonImageOnly: false,
          dateFormat: 'dd-mm-yy',
          yearRange: '1950:2050',
          //maxDate:"0",
          buttonText:"Select Date",
          onSelect: function(selected) {

          }
        });

  $( "#expiryDate" ).datepicker({
              changeMonth: true,
              changeYear: true,
              showOn: "button",
              buttonImage: "images/date-picker.png",
              buttonImageOnly: false,
              dateFormat: 'dd-mm-yy',
              buttonText:"Select Date",
              yearRange: '1950:2050',
              minDate:"+6M",
               onSelect: function(selected) {
                   var expiryDate = $(this).datepicker().val();
                   alert(expiryDate);


               }
        });

1 个答案:

答案 0 :(得分:0)

给你提供想法

$( "#issueDate" ).datepicker({
         changeMonth: true,
          changeYear: true,
          showOn: "button",
          buttonImage: "images/date-picker.png",
          buttonImageOnly: false,
          dateFormat: 'dd-mm-yy',
          yearRange: '1950:2050',
          //maxDate:"0",
          buttonText:"Select Date",
          minDate:new Date(),
          onclose: function(selected) {
                   $( "#expiryDate" ).datepicker({
              changeMonth: true,
              changeYear: true,
              showOn: "button",
              buttonImage: "images/date-picker.png",
              buttonImageOnly: false,
              dateFormat: 'dd-mm-yy',
              buttonText:"Select Date",
              yearRange: '1950:2050',
              minDate:new Date($.datePicker.getDate()+ 6M)
               onSelect: function(selected) {
                   var expiryDate = $(this).datepicker().val();
                   alert(expiryDate);


               }
        });
          }
        });