简体   繁体   English

如何在充满行的表上使表行淡出

[英]How to make a table row fadeOut on a table full of rows

Hey guys so I have a list populated by php and here is the layout: 大家好,我有一个用php填充的列表,这是布局:

<table>
     <tr>
        <td>
        ....
        <td>

    </tr>

    <tr class='firsttr' style='background:gray;'>
     <td>Remove selected</td>
     <td>First Name </td>
     <td>Last Name </td>
     <td>Email </td>
     <td>Phone </td>
     <td>Username </td>
     <td>Password </td>
     <td>Status </td>
     <td>Status Change Date</td>
     <td>#</td>
    </tr>


       <tr class='search-fade'> <!-- this is the part that I need to fade out based on which button was clicked for that user. -->
              <td>
        <input type='button' value='Remove employee'  name='cancelmember' class='cancelmember' />
      </td>
        //....table data    
               <td>
               $csvusername
    <input type='hidden' value='$csvusername'  name='username' class='removeemp-user'/>
    </td>                           
          </tr>                         
</table>

Here is my Jquery: 这是我的Jquery:

$(".cancelmember").click(function () {
        remove_name = $(this).parent().parent().find(".removeemp-user");


        $.ajax({
        type: "POST",
        dataType: "json",
        url: '/pcg/removemem.php',
        data: {
            'username': remove_name.val()
        },
        success: function(){
            alert("Employee Removed"),
            $(this).find(".search-fade").fadeOut()
        }
      });
    });

This above code works great I just can't figure out how to fade out the <tr class='search-fade'> If you could give me a hand I would appreciate it! 上面的代码很好用,我只是想不出如何淡出<tr class='search-fade'>如果您能帮帮我,我将不胜感激!

David 大卫

You need to cache the element so you can use it inside the success function. 您需要缓存元素,以便可以在成功函数中使用它。 You need to traverse up and not down the dom tree to find the table row because the button is a descendant of the tr 您需要遍历而不是下移dom树来查找表行,因为按钮是tr的后代

$(".cancelmember").click(function () {
    remove_name = $(this).parent().parent().find(".removeemp-user");
    var $this = $(this); // <-- cache the current element

    $.ajax({
        type: "POST",
        dataType: "json",
        url: '/pcg/removemem.php',
        data: {
            'username': remove_name.val()
        },
        success: function () {
            alert("Employee Removed"),
            $this.closest(".search-fade").fadeOut(); // <-- use closest since button is descendant of table row
        }
    });
});

Try this, 尝试这个,

$(".cancelmember").click(function () {
        remove_name = $(this).parent().parent().find(".removeemp-user");
        var $this = $(this); //Make sure this is parent element not button. You may have to adjust the element here

        $.ajax({
        type: "POST",
        dataType: "json",
        url: '/pcg/removemem.php',
        data: {
            'username': remove_name.val()
        },
        success: function(){
            alert("Employee Removed"),
            $this.find(".search-fade").fadeOut()
        }
      });
    });

$(this) refers to the button that was clicked, so unless the table rows are decendents of the button in the DOM, $(this).find(".search-fade") will not find them. $(this)是指被单击的按钮,因此,除非表行是DOM中该按钮的后代,否则$(this).find(".search-fade")不会找到它们。

You shoud change $(this) to a parent element of the table row. 您应该将$(this)更改$(this)表格行的父元素。

$(".cancelmember").click(function () {
        remove_name = $(this).parent().parent().find(".removeemp-user");
        var thisEL = $(this).parent().parent();

        $.ajax({
        type: "POST",
        dataType: "json",
        url: '/pcg/removemem.php',
        data: {
            'username': remove_name.val()
        },
        success: function(){
            alert("Employee Removed"),
            thisEL.fadeOut();
        }
      });
    });

You need to go 2 levels up. 您需要上2级。
tr.search-fade <- this needs to fade out tr.search-fade <-这需要淡出
---- td ---- td
--------- input.cancelmember <-click happened here --------- input.cancelmember <-单击发生在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery隐藏表行hide()vs fadeOut()条带表 - Jquery hiding table rows hide() vs fadeOut() stripe table 如何使用 Jquery 隐藏表的整行 - How to hide full row of the table using Jquery 有没有办法使表格行与最高表格行具有相同的高度 - Is there a way to make table rows the same height as the highest table row 如何制作桌子 <td> 和 <tr> 全屏宽度? - How to make Table <td> and <tr> full width? 如何删除表行到其他行的末尾 - How to remove the table row to the end of other rows 如何在表javascript中每3行添加一行 - How to add a row in every 3 rows in table javascript 如何在单击按钮时向表添加动态行,以及如何使用Ember单击以使现有行可编辑 - How to add a a dynamic row to table on click of a button, and make the existing rows editable on click using Ember 如何使表格行可点击以显示隐藏的行内容? - How do I make a Table rows clickable to show hidden row contents? 如何使具有相同功能但用于不同行的表中的行中的按钮可单击(不添加/删除/编辑) - How to make a button clickable in rows in the table with same functionality but for different row (Not add/delete/edit) 如何使用Javascript创建一个包含可以复制的行的表(在该行之后添加一行,包含相同的新行)? - How to make a table with rows that can be copied (adding a new row after that one, containing the same) with Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM