我正在使用CakePHP 2.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(' - ',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没有显示。
答案 0 :(得分:1)
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
}