I have a table:
<tr>
<td><div class="form-group"><div id="date" class="input-group date"><input type="text" class="form-control"><span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span></div></div></td>
<td><a href="#" class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-trash"></span></a></td>
</tr>
I use the button to create a new row dynamically:
$("#addInt").click(function() {
$("#intTbl").each(function () {
var tds = '<tr>';
$.each($('tr:last td', this), function () {
tds += '<td>' + $(this).html() + '</td>';
});
tds += '</tr>';
if ($('tbody', this).length > 0) {
$('tbody', this).append(tds);
} else {
$(this).append(tds);
}
});
});
I use bootstrap-datetimepicker
to create date field in the form, but when I dynamically add a new row, the date field is not working.
Try this :
<tr>
<td><div class="form-group"><div class="input-group date"><input type="text" class="form-control"><span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span></div></div></td>
<td><a href="#" class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-trash"></span></a></td>
</tr>
$('body').on('focus',".date", function(){
$(this).datetimepicker();
});
Instead of :
$('#date').datetimepicker();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.