【发布时间】:2014-10-29 14:05:47
【问题描述】:
我不确定为什么会发生这种情况,我列出了两种方式,一种是代码有效,另一种无效。 如果可能的话,我想用 THIS 获取 EACH 内部的值,以便我可以更改该值,但我可以从外部选择它们,为所有 IMG 做一个 each,这使我失去了与该相关联的 TD 的参考图片。
http://jsfiddle.net/4w8030th/1/
// Cannot retrieve SRC inside IMG tag
$.each($('tr.infraTrClara'), function () {
// Post-It
var postit = $(this).children('td:nth-child(2)').select('img');
postit_src = $(postit).attr('src');
alert(postit_src);
});
// Can retrieve SRC inside IMG tag
$.each($('tr.infraTrClara td:nth-child(2) img'), function () {
// Post-It
var postit = $(this).attr('src');
alert(postit);
});
【问题讨论】:
-
将
.select更改为.find。
标签: javascript jquery jquery-selectors this attr