gpt4 book ai didi

jquery - 使用 jQuery 迭代表格单元格并附加到 div

转载 作者:行者123 更新时间:2023-12-01 01:54:18 25 4
gpt4 key购买 nike

我真的很困惑..我正在尝试从表中获取值并将这些值添加到带有类标题的 div 中附加函数和.text函数。问题是,当我使用每个函数时,表中的最后一个值会被附加并且其余的就跳过了。。这是我的代码:

<script type="text/javascript">
$(document).ready(function() {
$('#nameGridView tr').each(function() {
if (!this.rowIndex) return; // skip first row
var productName = this.cells[0].innerHTML;
$('.title').each(function (i, obj) {
$('.title').html(productName);

});

});
});

</script>

请告诉我如何迭代每个表并同时添加,例如第一个 div 标题、表中的第一个值被附加等等。谢谢。

最佳答案

使用append()附加到元素。还可以使用 .eq() 获取与行具有相同索引的 div。

<script type="text/javascript">
$(document).ready(function() {
var $title = $('.title');
$('#nameGridView tr').each(function(i) {
if (!this.rowIndex) return; // skip first row
var productName = this.cells[0].innerHTML;
$title.eq(i-1).append(productName);
});
});

</script>

关于jquery - 使用 jQuery 迭代表格单元格并附加到 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14362457/

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