如何在PhoneGap / Android中实现DATE PICKER?

我试图在android中实现日期选择器。 我想让它获取数据并以文本格式显示

     function dateTest() { var myNewDate = new Date(); 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(); }); }    
DatePicker Test

我将其作为警报获取…但无法将其作为字符串存储在同一页面上

为什么要放松你的头?

总是会依赖设备对它的解释,在某些Android设备中它甚至不起作用,

有很多插件,插件,无论如何,它,

我个人喜欢,并使用mobiscroll: 链接

编辑:现在支付Mobiscroll但是有大量免费的前端移动框架,并且可能所有这些框架都有一个日期选择器,例如jQuery Mobile-datepicker 。

您的currentField似乎未定义。 在AVD上运行之前,您是否检查过Chrome控制台? 请尝试发布您尝试显示日期的元素。

现在,我假设您正在尝试执行以下代码所执行的操作

 $('.nativedatepicker').focus(function(event) { var currentField = $(this); var myNewDate = new Date(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); var newString = newDate.toString(); newString = newString.substring(0,15); currentField.val(newString); // 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(); }); }); 

要素如下

  

奇迹般有效 !! 希望能帮助到你 !!

我想要发生的事情很简单 – 我只想在点击某个字段时显示一个日期选择器。

然而,和Aleks一样,我不知道在我的html中放什么,如何在html中使用它,以及我应该在html中放置什么以在某些输入上调用datepicker。

插件中的文档不完整。

我找到了这个测试项目的解决方案。 步骤如下:

  1. 先决条件: 安装phonegap / cordova-cli
  2. 安装Cordova的设备插件: $ cordova plugin add org.apache.cordova.device
  3. 安装Dirk的datepicker插件: $ cordova plugin add https://github.com/DURK/cordova-datepicker-plugin
  4. 从测试项目中复制nativedatepicker.js并将其放在项目的js文件夹中。 这个文件有showDatePicker(), showDateTimePicker()方便函数。
  5. 添加ff。 到index.html代码:

注意:在浏览器中测试时,日期选择器不会显示

 .... 
....

这是我的工作实施。 输入类型是文本,只读。

 $('.nativedatepicker').focus(function(event) { var currentField = $(this); var myNewDate = new Date(); window.plugins.datePicker.show({ date : myNewDate, mode : 'date', allowOldDates : true }, function(returnDate) { var array = returnDate.split("/"); var day = array[2], month = array[1]; if (day <= 9) day = "0" + day; if (month <= 9) month = "0" + month; currentField.val(array[0] + "/" + month + "/" + day); currentField.blur(); }); }); 

如果有可用的日期选择器,您为什么要实现自定义日期选择器?

您只需使用来创建常用的iOS日期选择器。

有关移动设备上输入字段的更多信息,我建议: http : //blog.teamtreehouse.com/using-html5-input-types-to-enhance-the-mobile-browsing-experience