2015-06-27 23 views
2

基本上我有利用重力形式我的WordPress網站創建一個大的形式之前。我的表單中的一部分包含一系列以「開始日期」和「結束日期」列出的項目 - 示例:重力形式 - 日期選擇器 - 不允許結束日期早於開始日期

項目|開始日期|結束日期

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

什麼我後,使得它,所以我可以禁止從被選擇的「開始日期」之前的「截止日期」。這將是最好的,如果用戶無法連選擇的日期選取器日期降了下來,但如果它必須是在提交彈出一個錯誤,那就是罰款。我一直在研究這個問題好幾個小時,而我只是太小白,不知道該怎麼做。感謝您的幫助!

回答

0

嘗試這樣的事情,它使用jQuery的日期選擇器功能:

<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">

相關問題