doucao1888 2014-12-18 05: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

  1. $(document).on('click', '#deleteRow', function() {
  2. $(this).parent().parent().remove();
  3. });

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 05: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:

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

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

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部