//显示所有订单
//我想获得每个选择的价值
$.ajax({
url: 'http://www.api.verdulero.com/index.php/api/Pedidos/mostrar_fila? id_pedido='+id_pedi,
type:'get',
success: function(response){
$("#tableOrder").show();
//在表格中显示每个记录
$.each(response, function (index,producto){
$("#displayOrder").html('');
ap += "<tr>";
ap += "<td>"+producto.cantidad+"</td>";
ap += "<td>"+producto.unidad+"</td>";
ap += "<td>"+producto.producto_nombre+"</td>";
ap += "<td>"+producto.fecha_entrega+"</td>";
ap += "<td></td>";
ap += "<td><button type='button' id='borrar' class='btn btn-danger' value='"+producto.id+"'>Borrar</button></td>";
ap += "</tr>";
});
$("#displayOrder").append(ap); // display the orde
[R
//删除订单的功能。
$("#displayOrder button").each(function(){
var i = $(this).val();
$("#displayOrder").on("click","button", function(){
alert(i);
return false;
});
});
}
//成功结束显示顺序
答案 0 :(得分:1)
不需要为事件监听器遍历所有按钮。您可以注册一次,并计算所有这些。见下面的代码:
// event delegation used
// target all the button inside #displayOrder
$("#displayOrder").on("click","button", function(){
// this is how you captured button's value
// which in your case is a product ID
var btnValue = $(this).val();
// and this to remove button's row(clicked button row)
$(this).closest('tr').remove();
});
答案 1 :(得分:0)
尝试:
$("#displayOrder").click('button', function(){
$(this).parent().parent().remove();
});