重力形式 - 日期选择器 - 禁止结束日期在开始日期之前

时间:2015-06-27 22:35:45

标签: php jquery wordpress date gravity-forms-plugin

基本上我使用Gravity Forms在我的WordPress网站上创建了一个大表单。我的表单的一部分列出了一系列项目,其中包含“开始日期”,后跟“结束日期” - 示例:

项目|开始日期|结束日期

项目#1 | 05/01/2015 | 2015年5月25日

我正在制作它所以我可以禁止'结束日期'在选定的'开始日期'之前。如果用户甚至无法从日期选择器下拉菜单中选择日期,那将是最好的,但如果它必须是提交时弹出的错误,那就没问题了。我已经研究了好几个小时了,我只是太老了,不知道该做什么。感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

尝试使用jQuery的datepicker函数:

  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
  <script>
  $(function() {
    $( "#from" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 3,
      onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );
      }
    });
    $( "#to" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 3,
      onClose: function( selectedDate ) {
        $( "#from" ).datepicker( "option", "maxDate", selectedDate );
      }
    });
  });
  </script>
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to">

相关问题