gpt4 book ai didi

javascript - 基于条件的动态行选择

转载 作者:行者123 更新时间:2023-12-02 22:12:27 26 4
gpt4 key购买 nike

enter image description here在这种情况下,我必须遍历所有表行并选择该行的第一个实例,其中它有一个警告指示器,如所附图像所示。带有警告指示符的行将具有额外的 div,如下所述。

最佳答案

由于我无法清楚地看到您的完整 DOM,因此我将向您介绍如何迭代这些行并返回带有关联警告的行 -

var allTr = document.getElementsByClassName("classNameOnTr");

Array.prototype.forEach.call(allTr, function(tr) {
// all tds within a tr
var trAllTd = tr.children;

// first td out of all
var firstTd = trAllTd[0];

if(firstTd.children[0]) {
// this is the probable div which creates the warning indicator
// write your logic to check if the div exist here
// break the loop if you find it here and return the td
}
});

注意:我已经编写了冗长的代码,以便让您更多地了解如何进行操作。如果您理解得很好,可以将其缩短一两行。

关于javascript - 基于条件的动态行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59517505/

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