Problem with dynamic table when deleting

0

I have a dynamic table to which I add a record from an add button, and in the row the confirm appears, if so, the row with a edit and delete bootn is inserted. To delete I have a confirmation message but it appears once for each record in the table, I guess because I'm using classes, in what way could I use an id?

$("#agregarc").click(function(){
  
    var datoscheque='<tr><td><div>'+
    '<select id="bancos"><option value"=0">Seleccione<option></select></div></td>'+
    '<td><input type="text" class="form-control" id="nrocuenta" placeholder="CtaBancaria"/>'
    +'</td>'+
    
    '<td><input type="text"class="form-control" id="titular" placeholder="Titular"/></td>'+
  +'<div>'+'<td><input type="text" class="form-control" id="CUITCHEQUE" placeholder="CUIT"/></td>'+
  '<td><input type="text"class="form-control" id="Importe" placeholder="Son pesos"/></td>'
    +
    '<td><input type="date" class="form-control" id="fechacobro"placeholder="Deposito el:"/></td>'+
 
    '<td><button id="acreditar" class="btn btn-primary"><span id="acreditar" class="glyphicon glyphicon-ok"></span></button></td></tr>';


var acreditado = ($("#cheques tbody tr:last").find('button#acreditar').length === 0 || $("#cheques tbody tr").length === 0);
    if(acreditado){
       $(datoscheque).appendTo("#cheques");
       listarbancos(); 
    }else
    alert('complete e ingrese el registro actual');
  
  $("#acreditar").click(function(){
	 
    var Banco=$("#bancos").val();
    var Importe=$("#Importe").val();

    var nroCuenta=$("#nrocuenta").val();
    var titular=$("#titular").val();
    var fechacobro=$("#fechacobro").val();
   var CUIT=$("#CUITCHEQUE").val();
    
    var cobrado=0;
    var d = new Date();
    var fecharecibo=d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate();
   
    
  /*   $.ajax({
                                                        type: "POST",
                                                        url: "//localhost/gestionweb/includes/php/ingresacheque.php",
                                                        data: { "idbanco":Banco,"idc":idcliente,"num":nroCuenta,"fechar":fecharecibo,"fechac":fechacobro,"importe":Importe,"titular":titular,"cuenta":nroCuenta,"cobrado":cobrado,"CUIT":CUIT},
                                                   
                                            
                                                        error: function(){
                                                            alert("error petición ajax");
                                                           
                                                        },
                                                        
                                                        success: function(data){
                                                         
                                                            console.log(data); */
   

      
    
    var Bancot=$("#bancos").find('option:selected').text();
    var nroCuenta=$("#nrocuenta").val();
    var titular=$("#titular").val();
    var fechacobro=$("#fechacobro").val();
    
    var importe=$("#Importe").val();
 
    $("#cheques tbody tr:last td:eq(0)").html(Bancot);
    $("#cheques tbody tr:last td:eq(1)").html(nroCuenta);
    $("#cheques tbody tr:last td:eq(2)").html(titular);
    $("#cheques tbody tr:last td:eq(3)").html(CUIT);
    $("#cheques tbody tr:last td:eq(4)").html(importe);
    $("#cheques tbody tr:last td:eq(5)").html(fechacobro);
 $("#cheques tbody tr:last td:eq(6)").html('<td><button class="btn btn-primary "><span class="glyphicon glyphicon-pencil"></span></button></td><td>'+
'<button class="eliminar"><span class="glyphicon glyphicon-trash"></span></button></td><td>');



 $(".eliminar").on("click",function(){
    var opcionche = confirm("¿Desea eliminar cheque?");
    if (opcionche == true) {
   
    $(this).parents("tr").remove();} 

});
});
});
    
asked by Caruso 22.10.2018 в 15:35
source

0 answers