我遇到了一个问题,我想创建多个时间字段,但是单击添加按钮就像添加动态输入字段一样 . 但是当我在动态创建的输入字段上触发时间时,它不起作用 . 请帮助我附上下面的代码片段以供参考 .
<div class="row slot-container">
<div class="input-field col s12">
<input type="text" placeholder="select date for demo" class="datepicker">
</div>
<div class="input-field col s6">
<input type="text" placeholder="from" class="timepicker">
</div>
<div class="input-field col s6">
<input type="text" placeholder="to" class="timepicker">
</div>
</div>
<a class="waves-effect waves-light btn addSlots">Add Slots</a>
$(function(){
$('.timepicker').pickatime({
default: 'now', // Set default time: 'now', '1:30AM', '16:30'
fromnow: 0,
twelvehour: true, // Use AM/PM or 24-hour format
donetext: 'OK', // text for done-button
cleartext: 'Clear', // text for clear-button
canceltext: 'Cancel', // Text for cancel-button,
container: 'body', // ex. 'body' will append picker to body
autoclose: false, // automatic close timepicker
ampmclickable: true, // make AM PM clickable
aftershow: function(){} //Function for after opening timepicker
});
$(document).on('click','.addSlots',function(){
$('.slot-container').after("<div class='row slot-container'><div class='input-field col s6'> <input type='text' placeholder='from' class='timepicker'> </div> <div class='input-field col s6'> <input type='text' placeholder='to' class='timepicker'> </div> </div>");
});
});
2 回答
只是改变了第一行 . 之前:
后:
请试试