2012-05-03 127 views
0

我需要找到单击另一个图像按钮(在表格单元格2内)的图像按钮(在表格单元格1内)的id。如何使用jquery在html表中找到元素的ID

我无法在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> 
+1

u能请提供的HTML代码? –

+0

@Umesh请找到最新的问题。 – NewBie

回答

1

如果我理解正确的话,你需要从点击图像找到输入的ID? 如果是这样,那么这将你做它:

function changeImage(self) { 
    $(self).closest('tr').find('td input').attr('id'); 
} 
+0

现在试试你的解决方案。 – NewBie

+0

谢谢你天才。有效。 – NewBie

1
function changeImage(me){ 
    alert(me.id) 
} 
+1

我想他想要在这个函数内输入的id,而不是图像本身的id。 –

+0

确定在这种情况下它会是$(我).parent()。下一步()。找到(“输入”)。attr(“id”) – Sethunath

+0

看到我的回答;) –

0

下面的代码必须解决您的问题:

function changeImage(elm) { 
    var otherImageId = $(elm).parent().next().find("input:first").attr("id"); 

    // ... use otherImageId here ... 
} 
+0

它应该是'input:first'而不是'input:fist' - 至少如果你不想对你的输入元素进行性骚扰。 –

+0

感谢您的更正,@DanielBaulig。 –

相关问题