2014-05-01 153 views
0

我使用CakePHP 2.4.1并试图动态添加输入字段来形成。这工作正常,但Datetimepicker不显示。这里是我的代码:Jquery日期时间选择器不显示在输入字段中添加Jquery

<?php echo $this->Form->create('Event', array('novalidate' => true)); ?> 
<fieldset> 
    <legend><?php echo __('Admin Add Event'); ?></legend> 
<?php 
    echo $this->Form->input('name'); 
?> 
</fieldset> 

<h2>Terms</h2> 
<table id="mytable"> 
<tr><th></th><th>From</th><th>To</th><th>End Register</th><th>Location</th></tr> 
<tr id="term0" style="display:none;"> 
    <td><?php echo $this->Form->button('&nbsp;-&nbsp;',array('type'=>'button','title'=>'Click Here to remove this term')); ?></td> 
    <td><?php echo $this->Form->input('unused.from',array('label'=>'', 'type' => 'text')); ?></td> 
    <td><?php echo $this->Form->input('unused.to',array('label'=>'', 'type' => 'text')); ?></td> 
    <td><?php echo $this->Form->input('unused.register_end',array('label'=>'', 'type' => 'text')); ?></td> 
    <td><?php echo $this->Form->input('unused.location_id',array('label'=>'')); ?></td> 
</tr> 
<tr id="trAdd"><td> <?php echo $this->Form->button('+',array('type'=>'button','title'=>'Click Here to add another term','onclick'=>'addTerm()')); ?> </td><td></td><td></td><td></td><td></td></tr> 
</table> 

<?php echo $this->Form->end(__('Submit')); ?> 

<script type='text/javascript'> 
var lastRow=0; 

function addTerm() { 
    lastRow++; 
    $("#mytable tbody>tr:#term0").clone(true).attr('id','term'+lastRow).removeAttr('style').insertBefore("#mytable tbody>tr:#trAdd"); 
    $("#term"+lastRow+" button").attr('onclick','removeTerm('+lastRow+')'); 
    $("#term"+lastRow+" input:first").attr('name','data[Term]['+lastRow+'][from]').attr('id','from'+lastRow); 
    $("#term"+lastRow+" input:eq(1)").attr('name','data[Term]['+lastRow+'][to]').attr('id','to'+lastRow); 
    $("#term"+lastRow+" input:eq(2)").attr('name','data[Term]['+lastRow+'][register_end]').attr('id','end_register'+lastRow); 
    $("#term"+lastRow+" select").attr('name','data[Term]['+lastRow+'][location_id]').attr('id','termLocationId'+lastRow); 
} 

function removeTerm(x) { 
    $("#term"+x).remove(); 
} 

<script> 
$("#from0, #from1, #from2, #from3, #from4").datetimepicker(); 
</script> 

<script> 
$('#to0, #to1, #to2, #to3, #to4').datetimepicker(); 
</script> 

<script> 
$('#end_register0, #end_register1, #end_register2, #end_register3, #end_register4').datetimepicker(); 
</script> 

可能有人帮助我吗?我不知道为什么datetimepicker不显示。

回答

1

jquery-ui上是否有任何widget名为datetimepicker? 嗯,这个代码只需添加datepicker,如果你使用jQuery UI的...如果你正在使用其他的插件,然后修改..

function addTerm() { 
    lastRow++; 
    $("#mytable tbody>tr:#term0").clone(true).attr('id','term'+lastRow).removeAttr('style').insertBefore("#mytable tbody>tr:#trAdd"); 
    $("#term"+lastRow+" button").attr('onclick','removeTerm('+lastRow+')'); 
    $("#term"+lastRow+" input:first").attr('name','data[Term]['+lastRow+'][from]').attr('id','from'+lastRow); 
    $("#term"+lastRow+" input:eq(1)").attr('name','data[Term]['+lastRow+'][to]').attr('id','to'+lastRow); 
    $("#term"+lastRow+" input:eq(2)").attr('name','data[Term]['+lastRow+'][register_end]').attr('id','end_register'+lastRow); 
    $("#term"+lastRow+" select").attr('name','data[Term]['+lastRow+'][location_id]').attr('id','termLocationId'+lastRow); 
    $('#from'+lastRow).datepicker(); // added 
    $('#to'+lastRow).datepicker(); //added 
    $('#end_register'+lastRow).datepicker(); //added 
} 
+0

我使用jQuery的Timepicker-附加组件:https://开头的github .com/trentrichardson/jQuery-Timepicker-Addon – user3027356

+0

只需调用'datetimepicker'而不是'datepicker' –

+0

非常感谢。有用。 – user3027356

相关问题