我试图在表格单元格中获取图像右侧 td="description"标题/标题的内容。
并将其添加到 img 下方并像以前一样继续流程。
到目前为止我已经:
<script>
$('tr').each(function() {
var desc = $(this).$('td.description').html()
$(this).$('td.image').append(desc);
$('td.description').remove();
});
$("table#shopping-cart-items tr td.image").after($('<td id="clearSpace"></td>'));
});
</script>
如果我把“this”拿出来 - 它正确地捕获它并附加它 - 但所有的名称都是相同的;所以我对 $(this) 的使用我认为会破坏它,我还添加了 $('tr').each 函数?
感谢您的宝贵时间!
最佳答案
尝试正确使用$(this)
,
$('tr').each(function() {
var desc = $('td.description', this).html()
$('td.image', this).append(desc);
$('td.description', this).remove();
});
你的遍历方式是错误的。默认情况下,jquery 包装对象下没有名为 $
的函数。这就是你的代码被破坏的原因。
关于javascript - 无法选择 $(this).[TD 的元素] 并将其附加到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35875481/