helloxielan 2019-11-26 15:21 采纳率: 0%
浏览 22


This question already has answers here:
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/203198/event-binding-on-dynamically-created-elements" dir="ltr">Event binding on dynamically created elements?</a>
                            <span class="question-originals-answer-count">
                                (23 answers)
            <div class="grid--cell mb0 mt8">Closed <span title="2019-11-26 15:34:35Z" class="relativetime">5 months ago</span>.</div>

I call a function in a class named Preco2, as shown in the code.


$(function() {
  $('.Preco2').maskMoney({ decimal: '.', thousands: ' ', precision: 2 });


<td><input type="text" class="form-control Preco2" name="Preco2[]" id="Preco2" value="0.00"></td>

It works perfectly. But when I call the asynchronous request it no longer works. How can I solve?

Asynchronous request:

success: function(result)
       url: './atualizarencomendaaprovada',
       type: 'get',
       dataType: 'json',
       success: function(data){
            $("#employee_ta22 tbody").empty();
         var linha = ``; 
         for(let item of data){ 
         linha += `<tr id=${ item.Id }>          
         <td style="display:none"><input type="text" rows="4" name="teste2[]" id="teste2" value=${ item.Id }></td> 
         <td>${ item.DataAprovacao }</td> 
         <td>${ item.Identificacao }</td>   
         <td style="display:none"><input type="text" name="teste3[]" id="teste3" value=${ item.IdProduto }></td></td> 
         <td>${ item.Produto }</td>
         <td style="display:none"><input type="text" name="teste4[]" id="teste4" value=${ item.Quantidade }></td> 
         <td>${ item.Quantidade }</td> 
         <td><input min='0' oninput='this.value = Math.abs(this.value)' type="number" id="Unid" name="Unid[]"></td> 
         <td>${ item.Requerente }</td> 
         <td style="display:none"><input type="text" name="vale[]" value=${ item.IdDestino }></td>
         <td>${ item.Destino }</td> 
         <td>${ item.Fornecedor }</td> 
         <td><select class="form-control" name="EstadoFinal2[]"><option></option>
            $sql = "SELECT * FROM raddb.Status WHERE Id IN ('5', '6') ORDER BY Estado DESC";
            $qr = mysqli_query($conn, $sql);
            while($ln = mysqli_fetch_assoc($qr)){
            echo '<option value="'.$ln['Id'].'">'.$ln['Estado'].'</option>';
            <td><input type="text" class="form-control Preco2" name="Preco2[]" id="Preco2" value="0.00"></td>
            <td><textarea type="text" class="form-control" name="Apontamentos[]" rows="2"></textarea></td>
            <td><input type="text" class="form-control" name="Fatura[]"></td>
         $("#employee_ta22 tbody").html(linha); 
    "pagingType": "full_numbers", 
   "iDisplayLength": 5,                          
   "oLanguage": {
"sProcessing": "Aguarde enquanto os dados são carregados ...",
"sLengthMenu": "Mostrar _MENU_ registos por página",
"sZeroRecords": "Nenhum registo correspondente ao criterio encontrado",
"sInfoEmtpy": "Exibindo 0 a 0 de 0 registos",
"sInfo": "Exibindo de _START_ a _END_ de _TOTAL_ registos",
"sInfoFiltered": "",
"sSearch": "<span class='glyphicon glyphicon-search'></span>",
"oPaginate": {
   "sFirst":    "<span class='glyphicon glyphicon-fast-backward'></span>",
   "sPrevious": "<span class='glyphicon glyphicon-backward'></span>",
   "sNext":     "<span class='glyphicon glyphicon-forward'></span>",
   "sLast":     "<span class='glyphicon glyphicon-fast-forward'></span>"
  • 写回答

1条回答 默认 最新

  • weixin_33735077 2019-11-26 15:34

    That is because $('.Preco2') only checks for elements that already exist in the document, not those that will come in the future.

    Move that line inside the success callback of your $.ajax request, after you have added the data table to the document.




    • ¥15 pom文件依赖管理,未找到依赖
    • ¥15 现在后端返回给我一堆下载地址,都是一个视频切片后的,如何在uniapp安卓环境下将这些分片的视频下周并且合并成原始视频并下载到本地。
    • ¥15 Unity导出2D项目运行时图片变成马赛克
    • ¥15 关于communitytoolkit.mvvm的生成器得到的代码看起来没有被使用的问题
    • ¥15 matlab中此类型的变量不支持使用点进行索引
    • ¥15 咨询第六届工业互联网数据创新大赛原始数据
    • ¥15 Pycharm无法自动补全,识别第三方库函数接收的参数!
    • ¥15 STM32U575 pwm和DMA输出的波形少一段
    • ¥30 android百度地图SDK海量点显示标题
    • ¥15 windows导入environment.yml运行conda env create -f environment_win.yml命令报错