ie和FF 在insertRow和insertCell的区别

本文探讨了Internet Explorer (IE) 和Firefox (FF) 浏览器中使用insertRow和insertCell方法创建表格元素时存在的差异。特别指出在FF中需要指定-1作为参数以正确地在表格末尾添加行和单元格。
在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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

田猿笔记

写文章不容易,希望大家小小打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值