【问题标题】:Dynamic row selection based on a condition [closed]基于条件的动态行选择[关闭]
【发布时间】:2020-04-18 09:54:43
【问题描述】:

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

【问题讨论】:

  • 我已经编写了一个帮助代码来了解您如何去做。如果您有不明白的地方,请告诉我。

标签: javascript dom dynamic dom-manipulation


【解决方案1】:

由于我无法清楚地看到您的完整 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
    }
});

Note:我写了很长的代码来让你更清楚如何去做。如果你理解得很好,你可以将它缩短一两行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-20
    • 2018-08-15
    • 2021-04-15
    • 1970-01-01
    • 2019-12-30
    • 2022-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多