如何在tr中的最后一个td中为img标签添加事件或添加id属性 [英] how add event or add id attribute to img tag in last td in tr
本文介绍了如何在tr中的最后一个td中为img标签添加事件或添加id属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将属性ID 设置为以下突出显示的img标记或,以查找突出显示的img标记并添加onclick事件。
如何使用jQuery做到这一点?
I need to set attribute ID to following highlighted img tag or find highlighted img tag and add onclick event. How can I do that with jQuery?
<img src="/site/control/uploader/phpuploader/resources/stop.png" ...
<tbody>
<tr class="AjaxUploaderQueueTableRow" style="background-color: rgb(255, 255, 255);">
<td style="white-space: nowrap;">
<img src="/site/control/uploader/phpuploader/resources/circle.png" title="" width="16" height="16">
</td>
<td style="width: 456px;">Tales from the Dark 1 (2013).jpg</td>
<td style="white-space: nowrap;">
<img src="/site/control/uploader/phpuploader/resources/stop.png" title="Remove" width="16" height="16" style="cursor: pointer;">
</td>
</tr>
</tbody>
推荐答案
我不知道你想做什么,但是这个将使用jquery设置id:
I dunno when you want to do this, but this will set the id using jquery:
$('tr.AjaxUploaderQueueTableRow img:last').attr('id', 'yourID');
要找到最后一个td,然后找到img标签,可能不是最后一个:
To find last td and then find img tag, becuase img maybe not last:
$('tr.AjaxUploaderQueueTableRow td:last img').attr('id', 'yourID');
如果你想点击它并添加一个'高亮'类,那就是:
If you want to click on that and add a 'highlight' class, that would be:
var lastTlbImg = $('tr.AjaxUploaderQueueTableRow td:last img');
lastTlbImg.click(function(){
lastTlbImg.addClass('highlight');
})
这篇关于如何在tr中的最后一个td中为img标签添加事件或添加id属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文