在这种情况下,我必须遍历所有表行并选择该行的第一个实例,其中它有一个警告指示器,如附图所示。带有警告指示器的行将有额外的 div,如下所述。
1 回答
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:
我已经编写了冗长的代码,让您更了解如何去做。如果你理解得很好,你可以把它缩短一两行。
于 2019-12-29T07:36:43.553 回答