Well, I've assembled a dynamic form using JS. Within this form I have several input with class data
, where I call the datepicker. But they do not work, can anyone help me with this?
Follow the example below. Note that in non-dynamic input the datepicker works.
$('.data').datepicker({
'autoclose': true
});
function adicionarCampos() {
var objSelect = document.getElementById("numParcelas");
var i;
var linha = "";
// Cria os input
for (i = 0; i < objSelect.value; i++) {
// Monta HTML
linha += "\
<input type='text' name='data" + i + "' id='linha" + i + "' class='data' maxlength='10'>\n\
";
}
document.getElementById("txtParcelas").innerHTML = linha;
}
// Chama o evento
window.onload = adicionarCampos;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
Aqui o datepicker funciona
<input type='text' class='data'>
<br><br><br><br>
Gera o formulário
<input type='text' id='numParcelas' name='numParcelas' OnKeyUp="adicionarCampos()" value="1">
<br>
Aqui o datepicker não funciona<br>
<span id="txtParcelas"></span>