我正在使用Phonegap構建Android應用程序,並且我找到了我決定用於我的datepicker字段的this plugin。我按照說明操作,但運行時遇到了問題。Phonegap Android datepicker
這裏是我的代碼:
HTML:
<label for="schedule_start">Start date</label>
<input type="text" class="nativedatepicker" id="schedule_start" name="schedule[start_date]" value="{{start_date}}" required />
JS
FormView.prototype.defaultEvents = {
'focus .nativedatepicker': 'focusDatepicker'
};
// call when input focused
FormView.prototype.focusDatepicker = function(e) {
var currentField = $(this);
var myNewDate = Date.parse(currentField.val()) || new Date();
if(typeof myNewDate === "number"){ myNewDate = new Date (myNewDate); }
// 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("YYYY-MM-DD"));
// 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();
});
};
我已經添加了datePickerPlugin.js
到/assets/www/js/
和DatePickerPlugin.java
(我使用Backbone.js的)在創建com.phonegap.plugin
軟件包後輸入/src/com/phonegap/plugin/
。
我想我可能有一些問題調用datePickerPlugin.js,因爲我沒有得到我放在文件中的警報,但我不知道如何解決這個問題。
在此先感謝。
您是否在您的index.html文件中使用正確的路徑包含了datepickerplugin.js文件? – GenieWanted 2013-03-22 15:53:27