2014-05-01 116 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

相關問題