<table width="600" border="0" cellpadding="0" cellspacing="0" class="solid-bottom">
<tr>
<td width="600" height="20">
<table border="0" cellpadding="0" cellspacing="0" id="secTable">
<tr>
<td height="25" width="60" align="center" class="sec2" onclick="secBoard(0)">分钟</td>
<td width="60" align="center" class="sec1" onclick="secBoard(1)">小时</td>
<td width="60" align="center" class="sec1" onclick="secBoard(2)">天</td>
<td width="60" align="center" class="sec1" onclick="secBoard(3)">月</td>
<td width="60" align="center" class="sec1" onclick="secBoard(4)">周</td>
<td width="60" align="center" class="sec1" onclick="secBoard(5)">开始结束</td>
<td width="60" align="center" class="sec1" onclick="secBoard(6)">验证</td>
</tr>
</table>
</td>
<td width="20">
<script language="JavaScript" type="text/javascript">
function secBoard(n)
{
for(i=0;i<secTable.cells.length;i++)
secTable.cells[i].className="sec1";
secTable.cells[n].className="sec2";
for(i=0;i<mainTable.tBodies.length;i++)
mainTable.tBodies[i].style.display="none";
mainTable.tBodies[n].style.display="block";
}
</script>
</td>
</tr>
</table>
在火狐运行报错,在ie运行不报错。
报错行为:for(i=0;i<secTable.cells.length;i++)。
经过研究发现火狐不能用cells。
请问大家火狐中的cells用什么代替?
3 个解决方案
#2
var secTable = document.getElementById('table');
function secBoard(n) {
//table的设计是table.rows.cells,而不是table.cells,table.cells是设计是IE独有的
//测试了一下甚至IE6都没有table.cells
alert(secTable.rows[0].cells.length);
//后面的table.cells都是undefined异常
for (i = 0; i < secTable.cells.length; i++)
secTable.cells[i].className = "sec1";
secTable.cells[n].className = "sec2";
for (i = 0; i < mainTable.tBodies.length; i++)
mainTable.tBodies[i].style.display = "none";
mainTable.tBodies[n].style.display = "block";
}
#3
已解决。
function secBoard(n)
{
var secTable=document.getElementById("secTable");
for(i=0;i<secTable.rows[0].cells.length;i++)
secTable.rows[0].cells[i].className="sec1";
secTable.rows[0].cells[n].className="sec2";
for(i=0;i<mainTable.tBodies.length;i++)
mainTable.tBodies[i].style.display="none";
mainTable.tBodies[n].style.display="block";
}
#1
#2
var secTable = document.getElementById('table');
function secBoard(n) {
//table的设计是table.rows.cells,而不是table.cells,table.cells是设计是IE独有的
//测试了一下甚至IE6都没有table.cells
alert(secTable.rows[0].cells.length);
//后面的table.cells都是undefined异常
for (i = 0; i < secTable.cells.length; i++)
secTable.cells[i].className = "sec1";
secTable.cells[n].className = "sec2";
for (i = 0; i < mainTable.tBodies.length; i++)
mainTable.tBodies[i].style.display = "none";
mainTable.tBodies[n].style.display = "block";
}
#3
已解决。
function secBoard(n)
{
var secTable=document.getElementById("secTable");
for(i=0;i<secTable.rows[0].cells.length;i++)
secTable.rows[0].cells[i].className="sec1";
secTable.rows[0].cells[n].className="sec2";
for(i=0;i<mainTable.tBodies.length;i++)
mainTable.tBodies[i].style.display="none";
mainTable.tBodies[n].style.display="block";
}