Problems with JavaScript HTML function does not show content in page source code

1

For JavaScript functions that add HTML content, these added content is not being displayed in the source code of the page, even though it's working.

Example:

<html>
    <head>
        <script type="text/javascript" 
     src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script></head><body></body><script>$("body").append("<p>Apareço no carregamento normal, mas não no código fonte </p>");
</script>

</html>

I have a jQuery plugin for table, but it can not select the table because it does not have the columns yet and since I create the columns dynamically, I just can not use the plugin.

- EDIT-- My problem was in the asynchronous function of ajax. I had a function to activate the plugin, and before the function with ajax, since the function of ajax still did not return a value, I could not activate the plugin because the object did not exist yet. The solution was to put the plugin activation in ajax success

    
asked by anonymous 23.04.2018 / 02:28

1 answer

0

In order for the input type date to receive the value, you need to send in the form yyyy-MM-dd , see the snippet

function adicionar() {
    const tabela = $('#tabela');
     
    const ParcelaVencimento = $('#ParcelaVencimento').val();
    // Converti para numeros
    const ParcelaValor = $('#ParcelaValor').val();

    // Usei o sinal de + para transformar em numero
    const QtdParcela = +$('#QtdParcela').val();

    // Iniciei um novo array para armazenar os subtotatis
    const subtotal = [];

    let total = 0;
    let vencimento = new Date();
    vencimento.setDate( ParcelaVencimento )
    // Aqui voce criou o contador como sendo $i ao invés de count    
    for ( let cont = 0; cont < QtdParcela; cont++ ) {

        subtotal.push( ParcelaValor * 1 );
        total += subtotal[ cont ];
        vencimento.setMonth( vencimento.getMonth() + 1 )

        // Dica: utilize templateString para facilitar a criacao do HTML
        var linha = '<tr class='selected' id='linha${cont}'>    
                            <td> <button type='button' class='btn btn-warning' onclick='apagar('${cont}');'> X </button></td>
                            <td> <input type='hidden' name='cont[]' value='${cont}'>'${cont +1}'</td>
                            <td> <input name='ParcelaVencimento[]'  type='date' value='${formatDate(vencimento)}'></td>
                            <td> <input type='number' name='ParcelaValor[]' value='${ParcelaValor}'></td>
                            <td> <input type='number' name='QtdParcela[]' value='${QtdParcela}'></td> 
                        </tr>'
        tabela.append( linha );
    }
  
}

// Função para formatar a data
function formatDate(date) {
    var d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear();

    if (month.length < 2) month = '0' + month;
    if (day.length < 2) day = '0' + day;

    return [year, month, day].join('-');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>Parcelavencimento:<inputtype="text" value="12" id="ParcelaVencimento"><br />
Parcela Valor: <input type="text" value ="123.30" id="ParcelaValor"><br />
Quantidade Parcelas: <input type="text" value="12" id="QtdParcela"><br />

<button onclick="adicionar()"> Gerar tabela </button> <br />

<table id="tabela"></table>
    
23.04.2018 / 14:33