2013-07-19 14 views
1

你能告訴我如何阻止在類型=「日期」.in查詢手機中選擇未來日期嗎? 我有一個按鈕(+)的標題。點擊我打開彈出屏幕。有一個日期字段。我需要在日期選擇器(類型=「日期」)中阻止或隱藏未來的日期。如何阻止(禁用)在類型=「日期」.in查詢移動選擇未來日期?

這裏是小提琴 http://jsfiddle.net/Gajotres/7JqRG/6/

$(document).on('pagebeforeshow', '#Home', function(){ 
    $(document).on("popupafteropen", "#CaseInformationScreen",function(event, ui) { 
     var now = new Date(); 

     var day = ("0" + now.getDate()).slice(-2); 
     var month = ("0" + (now.getMonth() + 1)).slice(-2); 

     var today = now.getFullYear()+"-"+(month)+"-"+(day) ; 

     $('#caseDate').val(today);  
    });   
}); 

回答

2

工作例如:http://jsfiddle.net/Gajotres/7JqRG/9/

$(document).on('pagebeforeshow', '#Home', function(){ 
    $(document).on("popupafteropen", "#CaseInformationScreen",function(event, ui) { 
     var now = new Date(); 

     var day = ("0" + now.getDate()).slice(-2); 
     var month = ("0" + (now.getMonth() + 1)).slice(-2); 

     var today = now.getFullYear()+"-"+(month)+"-"+(day) ; 

     $('#caseDate').attr('max', today); 
     $('#caseDate').val(today);  
    });   
}); 

參考文檔:http://html5doctor.com/html5-forms-input-types/

不幸的是,因爲最大值和最小值不會在iOS在這裏工作也是一個JavaScript的解決了這個問題:http://jsfiddle.net/Gajotres/7JqRG/10/

var dateControler = { 
    currentDate : null 
} 

$(document).on('pagebeforeshow', '#Home', function(){ 
    $(document).on("popupafteropen", "#CaseInformationScreen",function(event, ui) { 
     var now = new Date(); 

     var day = ("0" + now.getDate()).slice(-2); 
     var month = ("0" + (now.getMonth() + 1)).slice(-2); 

     var today = now.getFullYear()+"-"+(month)+"-"+(day) ; 
     $('#caseDate').val(today); 
     dateControler.currentDate = today; 
    });   
    $(document).on("change", "#caseDate",function(event, ui) { 
     var now = new Date(); 
     var selectedDate = new Date($(this).val()); 
     if(selectedDate > now) { 
      $(this).val(dateControler.currentDate) 
     } else { 
      dateControler.currentDate = $(this).val(); 
     } 
    });  
}); 
+0

不工作在ipad上 – user2563256

+0

該死的,顯然iOs不支持最大和最小:http://stackoverflow.com/questions/8491198/ios-5-set-min-and-max-value-of-input-t ype-date,我會爲你創建一個javascript解決方案來解決這個問題。 – Gajotres

+0

的瀏覽器,它是在這裏工作沒有在ipad .. :( – user2563256

0

我們可以設置「最大」和「最小」的日期輸入型日期,使用屬性爲隱藏將來的日期。

$('#caseDate').attr("max",today); 
    $('#caseDate').attr("min",today); 
1

我們可以設置輸入類型中的最大和最小屬性,並以ISO格式分配日期(例如, 2010-08-14),第一年有四位數字,然後是月份,最後一位是月份的哪一天。

<input type="date" min="2010-08-14" max="2011-08-14" value="2010-08-14"/> 

請注意:

  • 的月份和日子必須始終用兩位數字寫(如01月份,而不是簡單1)
  • 它適用於Android的唯一
相關問題