您能否建议我使用与Android,Ios和Windows手机平台兼容的Phonegap DateTime Picker插件?
答案 0 :(得分:2)
我们有多个插件可用于datepicker,因为我已经尝试过,我建议你按照以下步骤使它工作,
第1步:运行以下命令
cordova plugin add https://github.com/mrfoh/cordova-datepicker-plugin
第2步:处理点击
$('.nativedatepicker').focus(function(event) {
var currentField = $(this);
var myNewDate = Date.parse(currentField.val()) || new Date();
// Same handling for iPhone and Android
window.plugins.datePicker.show({
date : myNewDate,
mode : 'date', // date or time or blank for both
allowOldDates : true
}, function(returnDate) {
var newDate = new Date(returnDate);
currentField.val(newDate.toString("dd/MMM/yyyy"));
// This fixes the problem you mention at the bottom of this script with it not working a second/third time around, because it is in focus.
currentField.blur();
});
});
$('.nativetimepicker').focus(function(event) {
var currentField = $(this);
var time = currentField.val();
var myNewTime = new Date();
myNewTime.setHours(time.substr(0, 2));
myNewTime.setMinutes(time.substr(3, 2));
// Same handling for iPhone and Android
plugins.datePicker.show({
date : myNewTime,
mode : 'time', // date or time or blank for both
allowOldDates : true
}, function(returnDate) {
// returnDate is generated by .toLocaleString() in Java so it will be relative to the current time zone
var newDate = new Date(returnDate);
currentField.val(newDate.toString("HH:mm"));
currentField.blur();
});
});
第3步:您可能需要将date.parse()的结果转换回对象,以使选择器第二次或第三次工作。如果是这样,请尝试在myNewDate声明后插入此代码:
if(typeof myNewDate === "number"){ myNewDate = new Date (myNewDate); }