<table class="content" border="1">
<tbody id="time_day">
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</tbody>
</table>
<script>
var th = document.getElementById('time_day').getElementsByTagName('th');
for (var i in th) {alert(i); }
</script>
结果是 0 1 2 3 4 5 6 item namedItem length 。。多了3个这玩意。
遍历的方法不对。不合适用for in
<table class="content" border="1">大神。 我知道这样就没问题了,但是我还是想知道下原理, 能说下吗?
小菜鸟在这谢谢了!
for in可以遍历对象,th获取到的对象包含了length长度属性,以及item,nameitem属性。
for把该对象当做数组遍历。是无法遍历对象的属性的。