2013-03-13 108 views
0

嗨,我有一個應用程序,用戶可以選擇開始日期時間和結束日期時間,如果他們想創建一個事件。 現在,這是一個html這裏我使用KendoUI日期時間插件:驗證與KendoUI日期時間

<div class="demo-section" style="width: 535px;"> 
       <label for="start">Start date:</label> 
       <input id="start" value="01/01/2013" /> 

       <label for="end" style="margin-left:3em">End date:</label> 
       <input id="end" value="01/01/2013"/> 
      </div> 
</li> 

<script type="text/javascript"> 
$(document).ready(function(){ 

function startChange() { 
    var startDate = start.value(); 
    if (startDate) { 
     startDate = new Date(startDate); 
     startDate.setDate(startDate.getDate()); 
     end.min(startDate); 
    } 
} 

function endChange() { 
    var endDate = end.value(); 

    if (endDate) { 
     endDate = new Date(endDate); 
     endDate.setDate(endDate.getDate()); 
     start.max(endDate); 
    } 
} 

var start = $("#start").kendoDateTimePicker({ 
    change: startChange, 
    parseFormats: ["MM/dd/yyyy"] 
}).data("kendoDateTimePicker"); 

var end = $("#end").kendoDateTimePicker({ 
    change: endChange, 
    parseFormats: ["MM/dd/yyyy"] 
}).data("kendoDateTimePicker"); 

start.max(end.value()); 
end.min(start.value()); 

}); 

問題是我不能得到驗證,因爲我想要的。假設用戶選擇From日期To日期應該顯示日期,這是大於當前選擇的日期From date.My currrent代碼似乎不工作。由於

+0

工作正常,請在此處查看:http://jsfiddle.net/OnaBai/meM5T/1/。什麼不行?您選擇哪個日期作爲「From」 – OnaBai 2013-03-13 08:24:06

回答

0

你是說,你要能夠比To選擇From日期更大,並且,當你做To應自動更新比From更大?

如果是這樣,你幾乎在那裏。您只需更新startChange函數即可更新相對於FromTo日期。

function startChange() { 
    var startDate = start.value(); 
    if (startDate) { 
     startDate = new Date(startDate); 
     startDate.setDate(startDate.getDate()); 
     end.min(startDate); 
     var endDate = end.value(); 
     if (endDate && endDate <= startDate) { 
      endDate.setDate(startDate.getDate() + 1); 
      end.value(endDate); 
     } 
    } 
} 

查看此jsFiddle的完整工作示例。