如何比较元素与[]的值

时间:2012-02-06 07:57:15

标签: javascript html getelementsbytagname

我正在尝试获取<tr>

中包含的<th>标记的计数

例如表格中有这些标签:

<th><tr></tr></th>
<th></th>
<th></th>
<th></th>

javascript:

var table = document.getElementById(tableId);    
var tbody = table.getElementsByTagName("tbody")[0];
var thead = tbody.getElementsByTagName("th");
var rowCount = 0;

for (i = 0; i < thead.length; i++) {
    if (thead[i].getElementsByTag("tr") === 'unidentified') rowCount++;
}

thead变量值应为= [tr],[],[],[]

但是rowCount值是4,它应该是1

我试图计算[] //看似空元素

的实际值是多少

我试过将thead [i] .getElementsByTag(“tr”)与null,空,“”,“[]”,“[]”进行比较 但结果是假的

0 个答案:

没有答案