2013-05-18 22 views
1

我在html中有一個Jquery日曆。它顯示從和迄今爲止。下面是我的代碼:Jquery Calendar禁用上個月問題

HTML頭部分代碼:

<link rel="stylesheet" href="jquery/jquery.ui.all.css"> 
<script src="jquery/jquery-1.9.1.js"></script> 
<script src="jquery/jquery.ui.core.js"></script> 
<script src="jquery/jquery.ui.widget.js"></script> 
<script src="jquery/jquery.ui.datepicker.js"></script> 
<link rel="stylesheet" href="../demos.css"> 


<script> 

$(function() { 
    $("#from").datepicker({ 
     defaultDate: "+1w", 
     changeMonth: true, 
     numberOfMonths: 1, 
     onClose: function(selectedDate) { 
      $("#to").datepicker("option", "minDate", selectedDate); 


     } 
    }); 
    $("#to").datepicker({ 
     defaultDate: "+1w", 
     changeMonth: true, 
     numberOfMonths: 1, 
     onClose: function(selectedDate) { 
      $("#from").datepicker("option", "maxDate", selectedDate); 
     } 
    }); 
}); 
</script> 

HTML機身碼:

<label for="from">From</label> 
<input type="text" id="from" name="from" class="tr"/> 
<label for="to">to</label> 
<input type="text" id="to" name="to" class="tr"/> 

嗯,這是工作的罰款。但是有可能從禁用過去的一個月到提交的名稱?我只是希望用戶不能從字段中選擇上個月到

如何將日曆工作現在: 如果用戶選擇從日即18-05-2013那麼迄今爲止開始18-05-2013,如果那麼它20-08-2013迄今爲止開始20- 08-2013。

+0

在一個側面說明看一看Kalendae:https://github.com/ChiperSoft/Kalendae – fmsf

+0

@fmsf其實我是jQuery的新功能,因此我的學習時間。 –

回答

2

您必須使用MINDATE參數

$("#from").datepicker({ 
    defaultDate: "+1w", 
    changeMonth: true, 
    numberOfMonths: 1, 
    minDate: new Date(), // <-------- this will disable all dates prior to the date passed there. 
    onClose: function(selectedDate) { 
     $("#to").datepicker("option", "minDate", selectedDate); 


    } 
}); 
+0

非常感謝。 @fmsf。它正在工作.. –