“博”技术之精,“客”网络之友。

博,客之博;客,博之客。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

[z]ie和FF 在insertRow和insertCell的区别

Posted on 2010-10-15 16:42  nect  阅读(324)  评论(0编辑  收藏  举报
在ie和FF中 insertRow和insertCell有着一个小小的区别,
有ie中可以这样调用:
var bgame_table = document.getElementById('game_table');
nowTR = bgame_table.insertRow();
nowTD = nowTR.insertCell();
但在ff中,上面这样调用就会报错了:
FF和ie都可以这要调用:
var bgame_table = document.getElementById('game_table');
nowTR = bgame_table.insertRow(-1);
nowTD = nowTR.insertCell(-1);
-1代表什么意思呢?
原来-1代表:插入(行)单元格到 cells(rows) 集合内的最后一个。
ie默认值了-1,但FF就没有默认值的。
所以为了兼容性好,我建议大家都是加上-1
例子:
<html>
<script>
function testinsert(){
var bgame_table = document.getElementById('game_table');
nowTR = bgame_table.insertRow(-1);
with(nowTR){
nowTD = insertCell(-1);
nowTD.className = 'b_hline';
nowTD.innerHTML ="00聯盟";

nowTD = nowTR.insertCell(-1);
nowTD.align = 'left';
nowTD.innerHTML ="1111a---队 b 队 了";
nowTD = nowTR.insertCell(-1);
nowTD.align = 'left';
nowTD.innerHTML ="222 b 队 了";
nowTD = nowTR.insertCell(-1);
nowTD.innerHTML ="3333a---队 了";

nowTD = nowTR.insertCell(-1);
nowTD.innerHTML ="4444a---队 了";
}

nowTR2 = bgame_table.insertRow(-1);
with(nowTR2){
nowTD = insertCell(-1);
nowTD.className = 'b_hline';
nowTD.innerHTML ="00聯盟";

nowTD = nowTR2.insertCell(-1);
nowTD.align = 'left';
nowTD.innerHTML ="1111a---队 b 队 了";
nowTD = nowTR2.insertCell(-1);
nowTD.align = 'left';
nowTD.innerHTML ="222 b 队 了";
nowTD = nowTR2.insertCell(-1);
nowTD.innerHTML ="3333a---队 了";

nowTD = nowTR2.insertCell(-1);
nowTD.innerHTML ="4444a---队 了";
}
}
</script>
<body onload="testinsert()">
<table id="game_table" width="526" border="0" cellspacing="1" cellpadding="0" class="b_tab" >
<tr class="b_tline_fu">
<td width="40" >時間</td>
<td width="200">主客a</td>
<!--<td width="40">suyi</td>-->
<td width="110" nowrap>foot</td>
<td width="110" nowrap>大小</td>
<td width="50">單雙</td>
</tr>
</table>
</body>
</html>