0

我正在創建一個應用程序,我想應用程序datepicker選擇生日,所以我試圖使用jquery-ui-timepicker-addon.js但問題是當我試圖在div中靜態使用它然後它顯示日期選擇器,但是當我嘗試動態創建它不工作時,任何人都可以告訴它爲什麼它的行爲像這樣,我犯了什麼錯誤 這裏是創建動態日期選擇器的代碼:jquery timepicker不工作在phonegap android

var creatText = $(document.createElement('input')).attr('type','text'); 
    creatText.attr('class','datetimepicker'); 
    creatText.attr('id','birthdate'); 
    creatText.attr('size','25'); 
    creatText.attr('placeholder','Birth Date'); 
    creatText.appendTo('#contentdemo'); 

這裏是靜態創建日期選擇器的代碼,它的工作正常:

<div data-role="content" id="contentDemo"> 
<div data-role="collapsible-set" data-content-theme="c" style="margin-left: 8px;margin-right: 8px" id="dynamic_actionform"> 
</div> 
    <input class='datetimepicker' placeholder="birth date" size='25'> 
</div> 

這裏是文件的即時通訊使用enter link description here 錯誤的logcat中的JS在github上的例子:

logcat09-05 06:37:41.943: D/CordovaLog(2822): Uncaught Error: no such method 'value' for slider widget instance 09-05 06:37:41.943: 

E/Web Console(2822): Uncaught Error: no such method 'value' for slider widget instance at file:///android_asset/www/js/jquery-1.7.1.js:552 

在此先感謝。

回答

0

我相信你需要調用.datetimepicker()的新元素你它添加到DOM後,像這樣:

$('#contentdemo').append('<input type="text" id="birthdate" size="25" placeholder="Birth Date">'); 

// This should initialize the datepicker functionality 
jQuery('#birthdate').datetimepicker(); 
+0

我嘗試過,但在logcat..08-30 12其示出錯誤:28:31.107:d/CordovaLog(6452):未捕獲的類型錯誤:無法讀取的未定義 08-屬性 'MSIE' 30 12:28:31.107:E/Web控制檯(6452):Uncaught TypeError:無法讀取屬性'msie'的未定義文件:///android_asset/www/js/jquery-ui.js:8753 –

+0

好的。它看起來問題在於你正在使用的jquery-ui版本。舊版本仍包含對不推薦使用的jQuery.browser屬性的引用。嘗試升級到jquery-ui 1.10以查看是否可以解決您的問題。 –

+0

我已經更新我的jquery-ui到v1.10.3知道它在logcat09-05 06:37:41.943中顯示這個錯誤:D/CordovaLog(2822):未捕獲錯誤:滑塊窗口部件實例沒有這樣的方法'值' 09 -05 06:37:41.943:E/Web控制檯(2822):未捕獲錯誤:在file:///android_asset/www/js/jquery-1.7.1.js:552處沒有用於滑塊小部件實例的此類方法'值' –

0
var creatText = $(document.createElement('input')).attr('type', 'text'); 
creatText.attr('class', 'datetimepicker'); 
creatText.attr('id', 'birthdate'); 
creatText.attr('size', '25'); 
creatText.attr('placeholder', 'Birth Date'); 
creatText.appendTo('#contentDemo'); 

$('.datetimepicker').datetimepicker() 

你當附加拼寫contentDemocontentdemo

Fiddle Example

+0

我沒有使用jquery-ui.datepicker.js即時通訊使用jquery-ui-timepicker-addon.js,它可以像滾動視圖中的android時間選擇器一樣獲取日期選擇器,以便用戶選擇brthdate變得更容易。 –

+0

基本上是一樣的東西。如果您要使用第三方庫,請鏈接到它們或創建一個包含它們的jsfiddle。我的問題是更新與jquery-ui-timepicker-addon.js – DGS

+0

如果我打電話給datetimepicker函數,那麼它的動態創建的字段在日誌中給出錯誤,但是母雞我點擊了我創建的靜態顯示的字段日期選擇器。 –