本文介绍了PHP-CodeIgniter:如何获取相应的html表行值由Javascript删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的codeigniter项目中,我使用一个表,它是由Ajax动态生成的。在每一行上都有一个按钮来从Html表和Mysql表中删除相应的行。

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.

我试过了。我得到代码删除Html表行,并按照

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();

});

但我想从Mysql也删除相应的行。所以首先,它需要从javascript传递相应的行信息。然后通过URL传递给控制器​​。

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;

如何获取相应的行信息,如company_id,lic_id(html表的字段名)。

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

推荐答案

将属性添加到< tr>

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

在您的jQuery中,获取这些属性点击删除链接:

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();
});

这篇关于PHP-CodeIgniter:如何获取相应的html表行值由Javascript删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:20