ajax删除后隐藏tr行

时间:2014-09-18 10:26:43

标签: ajax codeigniter

我试图删除codeigniter中的记录,使用ajax调用它的删除,但我无法从刚删除的表中隐藏该行。请帮帮我! 这是我的删除代码。

<script type="text/javascript">
$(document).ready(function(){
 $(".delete").click(function(){
   var id = $(this).attr('id');
   var btn=this;
   $.ajax({
      type:'POST',
      url:'<?=base_url()?>student/delete/',
      data:'id='+id,
      success:function(data) {
        if(data) {   
 //here i want to hide that tr tag which is just got deleted
        } else { 
        alert("no");
      }
   }
 });
});
});
</script>

2 个答案:

答案 0 :(得分:1)

你需要使用最接近的('tr')方法,一旦表中的记录被删除,只需使用这个最接近的('tr') 你也可以动画删除...这里是修改后的代码。这将是你的工作所希望的。

<script type="text/javascript">
$(document).ready(function(){
 $(".delete").click(function(){
   var id = $(this).attr('id');
   var btn=this;
   $.ajax({
      type:'POST',
      url:'<?=base_url()?>student/delete/',
      data:'id='+id,
      success:function(data) {
        if(data) {   
                $(btn).closest('tr').fadeOut("fast");
               //or $(this).closest('tr').fadeOut("fast");
        } else { 
        alert("no");
      }
   }
 });
});
});
</script>

答案 1 :(得分:0)

你可以使用$(&#34;#id-name&#34;)。remove();

相关问题