gpt4 book ai didi

javascript - 从第 n 个 td 元素中选择数据

转载 作者:行者123 更新时间:2023-12-03 12:35:42 27 4
gpt4 key购买 nike

我正在尝试从以下 html 中获取数据(“borgid”):

<tr style="cursor:default;" class="odd">
<td class=" ">1</td>
<td class=" ">What was your favorite childhood pet's name?</td>
<td data-borgid="1" class=" ">Generic Hospital Networks</td>
<td class=" ">5173</td>
<td style="text-align:right;" class=" "><input type="button" value="Remove" name="1" class="deleteMeCQ" style="cursor:pointer;"></td>
</tr>

我尝试了 $(':nth-child(2)', $(this)).data("borgid")$tds.eq(2)。数据(“borgid”)。两者都返回“未定义”。提前致谢。

另请参阅:Is there a way to combine $(this) with :nth-child?

var a = [];
$("#ChallengeQuestionsTable tbody tr").each(function () {

var $tds = $(this).children('td');

var questionid = '';
var question = '';
var borgid = '';

if ($tds.length == 5) {
questionid = $tds.eq(0).html();
question = $tds.eq(1).html();
borgid = $(':nth-child(2)', $(this)).data("Borgid");

a.push('{ "questionid" : "' + questionid + '", "question" : "' + question + '", "borgid" : "' + borgid + '" }');
}
});

最佳答案

如果你想获得borgid,可以通过现有属性选择:

borgid = $($(this).find("[data-borgid]").get(0)).attr("data-borgid");

关于javascript - 从第 n 个 td 元素中选择数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23745589/

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