Phonegap DateTime Picker插件与Android,Ios和Windows Phone平台兼容 [英] Phonegap DateTime Picker plugin compatible with platforms Android,Ios and Windows Phone

查看:92
本文介绍了Phonegap DateTime Picker插件与Android,Ios和Windows Phone平台兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能建议我任何与Android,Ios和Windows Phone平台兼容的Phonegap DateTime Picker插件吗?

Could you please suggest me any Phonegap DateTime Picker plugin that is compatible with platforms Android,Ios and Windows Phones?

推荐答案

我们有许多用于datepicker的插件,当我已经尝试过时,建议您按照以下步骤操作,

We have number of plugins avail for datepicker, As I tried this already, I would recommend you to follow below steps to make it work,

步骤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声明之后插入以下代码:

Step 3: You may need to convert the result of date.parse() back to an object to get the picker to work a second or third time around. If so, try inserting this code after the myNewDate declaration:

if(typeof myNewDate === "number"){ myNewDate = new Date (myNewDate); }

这篇关于Phonegap DateTime Picker插件与Android,Ios和Windows Phone平台兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆