我在单击 html 表内的按钮并获取同一行上的值并将其传递给输入 FullName 时遇到问题 .我怎样才能做到这一点?谢谢
<td><?php echo $r['signatoryname'] ?></td>
<td><?php echo $r['signatoryposition'] ?></td>
<td><?php echo $r['signatoryoffice'] ?></td>
<td>
<button type="button" class="btnedit btn btn-xs btn-success">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>Edit
</button>
</td>
<input id="Fullname" class="form-control" >
最佳答案
你可以这样使用,
$(".btnedit").click(function () {
var name = $(this).closest("tr").find("td:eq(0)").text();
$("#Fullname").val(name);
});
Closest("tr")
将返回点击按钮的父 tr。
然后您可以使用其索引找到子 td。
find("td:eq(0)")
将返回所选 tr
的第一个 td
。在您的情况下,它将返回 signatoryname。
同样,您可以使用 find("td:eq(1)")
& find("td:eq(2)")
关于javascript - 单击 html 表中的一个按钮并获取同一行的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33392054/