gpt4 book ai didi

javascript - 如何在 JQuery 中使用 replaceWith 在 for 循环中附加

转载 作者:行者123 更新时间:2023-11-29 20:58:44 25 4
gpt4 key购买 nike

我需要在 for 循环内附加表中的每个标记,但循环和 replaceWith 不起作用。

如何为每个 replacewith 或附加到目标迭代循环?

for ( z = 0; z < json[x].category[y].item.length; z++ ) {
html += '<td id="'+ json[x].category[y].item[z].idCat +'">';
html += '<div class="new-value">'+ json[x].category[y].item[z].value +'</div>';
html += '</td>';
}
$('table tr td.new').replaceWith(html);

最佳答案

像下面这样:-

count = 0;
for ( z = 0; z < json[x].category[y].item.length; z++ ) {
count++;
var html = ''; //define html variable first
html += '<td id="'+ json[x].category[y].item[z].idCat +'">';
html += '<div class="new-value">'+ json[x].category[y].item[z].value +'</div>';
html += '</td>';
$('table tr td.new:eq("'+count+'")').html(html); // use .html()
}

关于javascript - 如何在 JQuery 中使用 replaceWith 在 for 循环中附加 <td>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47836303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com