[英]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.