Jquery日期时间选择器未显示在随Jquery一起添加的输入字段中

Jquery日期时间选择器未显示在随Jquery一起添加的输入字段中,jquery,cakephp,Jquery,Cakephp,我正在使用CakePHP2.4.1,并试图动态地将输入字段添加到表单中。这工作正常,但Datetimepicker不显示。这是我的密码: <?php echo $this->Form->create('Event', array('novalidate' => true)); ?> <fieldset> <legend><?php echo __('Admin Add Event'); ?></legend>

我正在使用CakePHP2.4.1,并试图动态地将输入字段添加到表单中。这工作正常,但Datetimepicker不显示。这是我的密码:

<?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();
}

条款
自始至终寄存器位置
var lastRow=0;
函数addTerm(){
lastRow++;
$(“#mytable tbody>tr:#term0”).clone(true).attr('id','term'+lastRow).removeAttr('style').insertBefore(#mytable tbody>tr:#trAdd”);
$(“#term”+lastRow+“button”).attr('onclick','removetem('+lastRow+'));
$(“#term”+lastRow+“input:first”).attr('name','data[term]['+lastRow+'][from]').attr('id','from'+lastRow));
$(“#term”+lastRow+”输入:等式(1)”).attr('name','data[term]['+lastRow+'][to]')).attr('id','to'+lastRow);
$(“#term”+lastRow+”输入:等式(2)”).attr('name','data[term]['+lastRow+']][register\u end]')).attr('id','end\u register'+lastRow);
$(“#term”+lastRow+“select”).attr('name','data[term]['+lastRow+'][location\u id]').attr('id','termLocationId'+lastRow);
}
函数m(x){
$(“#term”+x).remove();
}


$(“#从0开始,#从1开始,#从2开始,#从3开始,#从4开始”).datetimepicker();
$(“#到0,#到1,#到2,#到3,#到4”).datetimepicker();
$(“#end#u register0,#end#u register1,#end#u register2,#end#u register3,#end#u register4”).datetimepicker();

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

在jquery ui上是否有名为
datetimepicker
的小部件? 如果您使用的是jquery ui,那么这段代码只需添加
datepicker
。。。如果您正在使用其他插件,请修改

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
}

我正在使用jQuery Timepicker插件:只需调用
datetimepicker
而不是
datepicker
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
}