简体   繁体   English

jQuery timepicker无法在phonegap android中工作

[英]jquery timepicker not working in phonegap android

I am creating an app in which i want to app datepicker to select birthdate so for that i tried to use jquery-ui-timepicker-addon.js but the problem is when i tried to use it statically in the div then it shows the dateselector but when i try to create it dynamically it's not working can any one tell why its acting like this and where i am making mistake here is the code for creating dynamic datepicker: 我正在创建一个应用程序,我想在其中选择日期选择器来选择生日,因此我尝试使用jquery-ui-timepicker-addon.js,但问题是当我尝试在div中静态使用它时,它显示了dateselector但是当我尝试动态创建它时,它无法正常工作,谁能说出为什么这样做,以及我在哪里出错了,这是创建动态datepicker的代码:

    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');

here is the code for creating date selector statically and its working fine: 这是用于静态创建日期选择器的代码,它可以正常工作:

<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>

here is the example in github for the js files im using enter link description here error in the logcat: 这是github中js文件im使用logcat中的enter link description here错误的示例:

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

Thanks in advance. 提前致谢。

I believe you need to call .datetimepicker() on the new element after you've appended it to the DOM like so: 我相信在将新元素添加到DOM后,需要像这样对新元素调用.datetimepicker():

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

// This should initialize the datepicker functionality
jQuery('#birthdate').datetimepicker();
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()

You spelt contentDemo as contentdemo when appending. 追加时,您将contentDemo拼写为contentdemo

Fiddle Example 小提琴的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM