工作例如: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();
}
});
});
不工作在ipad上 – user2563256
該死的,顯然iOs不支持最大和最小:http://stackoverflow.com/questions/8491198/ios-5-set-min-and-max-value-of-input-t ype-date,我會爲你創建一個javascript解決方案來解決這個問題。 – Gajotres
的瀏覽器,它是在這裏工作沒有在ipad .. :( – user2563256