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();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败