工作示例: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/
不幸的是,因为 max 和 min 在 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();
}
});
});