[英]How to find the id of an element in an html table using jquery
我需要在单击另一个图像按钮(表格单元格2内)时找到图像按钮的ID(在表格单元格1中)。
我无法在我的javascript / jquery中硬编码任何索引。
有没有其他方法来获取表的特定行中的第二个按钮的ID?
请帮忙
代码示例
<tr class="home-history-grid-row">
<td>
<img id="test" height="16px" width="16px" onclick="changeImage(this)" src="SiteImages/deleteconfirm.png" title="Confirm Delete" alt="Delete">
</td>
<td>
<input id="ctl00_Content_NotificationHistory_ctl02_ImgDelete" type="image" style="height: 16px; width: 16px; border-width: 0px;" src="SiteImages/X.gif" clientidmode="Static" disabled="disabled" name="ctl00$Content$NotificationHistory$ctl02$ImgDelete">
</td>
</tr>
function changeImage(me){
alert(me.id)
}
如果我理解正确,您需要通过单击图像找到输入的ID? 如果是这样,那么这将为您做到:
function changeImage(self) {
$(self).closest('tr').find('td input').attr('id');
}
以下代码必须解决您的问题:
function changeImage(elm) {
var otherImageId = $(elm).parent().next().find("input:first").attr("id");
// ... use otherImageId here ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.