I don’t know what you’re calling it datepicker()
, but you can add the class to the elements you want to add, it would look like this:
for (var i = 0; i < 5; i++) {//Coloquei o i como 5 apenas para testes
var new_date = new Date();
new_date.setMonth(new_date.getMonth() + i);
$("#divParcela").append("<div class='col-xs-4'> <label>Vencimento - parcela " + parseInt(i + 1) + "</label> <input type='text' class='datepicker' name='DataVencimentoParcela[]' id='DataVencimentoParcela" + parseInt(i + 1) + "' value='" + $.datepicker.formatDate('dd/mm/yy', new_date) + "' class='form-control' />");
};
And call the datepicker()
by the event focus()
jQuery. This would be the complete example:
$('body').on('focus',".datepicker", function(){
$(this).datepicker();
});
$(document).ready(function(){
for (var i = 0; i < 5; i++) {//Coloquei o i como 5 apenas para testes
var new_date = new Date();
new_date.setMonth(new_date.getMonth() + i);
$("#divParcela").append("<div class='col-xs-4'> <label>Vencimento - parcela " + parseInt(i + 1) + "</label> <input type='text' class='datepicker' name='DataVencimentoParcela[]' id='DataVencimentoParcela" + parseInt(i + 1) + "' value='" + $.datepicker.formatDate('dd/mm/yy', new_date) + "' class='form-control' />");
};
});
<script type="text/javascript" src="//code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/mint-choc/jquery-ui.css">
<div class="demo">
<p>Data Normal: <input id="datepicker" class="datepicker" type="text"></p>
</div><!-- End demo -->
Campos dinamicos:
<div id="divParcela">
</div>
Example in Jsfiddle
$( 'input). datepicker(); does not work?
– Marconi
It doesn’t work but has already been solved with Randrade’s suggestion.
– hard123