如何调用数据表行中添加的ID

问题描述 投票:0回答:1

我有模块列表中的数据表中的所有客户的详细信息,使用该按钮的动作。

问:为什么我不能得到的ID,我加入到该行的按钮,当我点击该按钮将不会将警报显示为什么会发生?

我这里有我的AJAX列出所有客户在表

    $(document).ready(function(){
  $.ajax({
    url:'/logic_get_customer_data',
    type: 'GET',
    dataType: 'json',
    success:function(response) {

      var details = response.data;
      $.each(details, function (index, el) {

          var stringify = jQuery.parseJSON(JSON.stringify(el));

          var customer_name_each = stringify['customer_name'];
          var customer_address_each = stringify['customer_address'];
          var customer_email_each = stringify['customer_email'];
          var customer_number_each = stringify['customer_number'];
          var store_location_each = stringify['customer_location'];
          var customer_order_note_each = stringify['customer_order_note'];
          var customer_registered_each = stringify['customer_registered'];
          var customer_id_each = stringify['customer_id'];
          var action_each = '<button id="show_cart_button" class="btn btn-primary" type="button" value='+customer_id_each+' data-toggle="modal" data-target="#add_cart" ><i class="fas fa-cart-arrow-down"></i></button>';

          var t = $( "#tables" ).DataTable();
          t.row.add([customer_name_each,
            customer_address_each,
            customer_email_each,
            customer_number_each,
            store_location_each,
            customer_order_note_each,
            customer_registered_each,
            action_each]).draw();

        })
    }

  });
});

我点击功能调用ID

$("#show_cart_button").click(function () {
  var fired_button = $(this).val();
  alert('George');
});
jquery json ajax datatable
1个回答
2
投票

因为它是DOM后添加。使用上的点击功能和目标的东西,是在DOM阿贾克斯开始前。

$("body").on("click", "#show_cart_button",function () {
  var fired_button = $(this).val();
  alert('George');
});
© www.soinside.com 2019 - 2024. All rights reserved.