doucao1888 2014-12-18 13:12
浏览 45
已采纳

PHP-CodeIgniter:如何通过Javascript删除相应的html表行值

In my codeigniter project i'm using a Table in which it is dynamically generated by Ajax. on the each row there is a button to Delete the corresponding row from Html Table and Mysql table too.

i tried it already. and i get the code to remove Html table row , and it follows

$(document).on('click', '#deleteRow', function() {

     $(this).parent().parent().remove();

});

and it worked. but i want to delete that corresponding row from Mysql too. so first of all , it needs to be pass the corresponding row informations from javascript. then pass this to the Controller via URL.?

window.location.href = "<?php echo base_url("settings/remove_company"); ?>?id="+current;

How i get corresponding row informations such as company_id, lic_id (field names of html table).? any help would be greatly appreciated .

  • 写回答

1条回答 默认 最新

  • dougehe2022 2014-12-18 13:16
    关注

    Add attributes to the <tr>

    <tr data-companyId="<?php echo $companyId;?>" data-licId="<?php echo $licId;?>">
    

    In your jQuery, get those attributes on click of delete link:

    $(document).on('click', '#deleteRow', function() {     
      var companyId = $(this).parent().parent().attr('data-companyId');
      var licId = $(this).parent().parent().attr('data-licId');
      $(this).parent().parent().remove();
    });
    

    Even, you can do object caching (using variable instead of object to improve performance.

    $(document).on('click', '#deleteRow', function() {
      var obj = $(this).parent().parent();
      var companyId = obj.attr('data-companyId');
      var licId = obj.attr('data-licId');
      obj.remove();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探