Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery在单击同一行的按钮时获取td值_Jquery - Fatal编程技术网

使用jquery在单击同一行的按钮时获取td值

使用jquery在单击同一行的按钮时获取td值,jquery,Jquery,表中有很多行,每行都有删除按钮。。单击“删除”按钮时,我试图获取两个td值。。它返回空值 Html是 <tr> <td> abc</td> <td> def</td> <td> <input type="button" class=" delete" value=" delete"></td> 有什么问题吗?当我们单击“删除”按钮时,它应该会得到其中第二行的td值。首

表中有很多行,每行都有删除按钮。。单击“删除”按钮时,我试图获取两个td值。。它返回空值

Html是

<tr>
   <td> abc</td>
     <td> def</td>
       <td> <input type="button" class=" delete"  value=" delete"></td>

有什么问题吗?当我们单击“删除”按钮时,它应该会得到其中第二行的td值。首先,您必须获得父项

jQuery(this).parents('tr').find("td:eq(1)").text();

你需要先回到父母那里,然后找到孩子

$('.delete')。在('click',function()上{
txt=$(this.parents('tr').find(“td:eq(1)”).text();
console.log(txt);
});

abc
def
试试这个

jQuery(this).closest('tr').find('td:eq(1)').text();
使用closest()函数并获取其父tr并查找“td:eq(1)”


你能提供你的代码片段吗?我真的很抱歉。。我使用mobilePossible发布此信息,请正确引用您的'td:eq(1)'
jQuery(this).closest('tr').find('td:eq(1)').text();
jQuery(this).closest('tr').find('td:eq(1)').text();