为什么下面的程序在IE6中可以运行,而在IE7中却运行不了,请哪位大侠帮帮忙啊。。
<script language="javascript">
var n=0; //初始化数组为0,之后随着变化
var fileCount=1;
var tempRow=0; //动态表格的临时行
var maxRows=0; //动态表格的临时列
var num = 1;
var fileCount=1;
//添加文件的主要方法
function addFile()
{
var str = '<a href="#" class="addfile" id="a' + num +'"><input id="file" type="file" size="50" class="addfile" onchange="addFile()" name="file[' + num + ']" ' + '/></a>';
var fileText;
var ary;
var fileTextValue;
fileText = document.all("file[" + n + "]").value; //获取文件名称
ary = fileText.split("\\");
fileTextValue = ary[ary.length-1];
if(checkfilename(fileTextValue)==false)
{
alert("此文件已经存在");
}
else
{
document.all("a" + n).style.display = "none";//将前一个 P 的子元素设为不可见
document.getElementById('file').insertAdjacentHTML("beforeEnd",str);
tempRow=fileTable.rows.length-1; //fileTable 就是那个动态的 table 的 ID 了
maxRows=tempRow;
tempRow=tempRow+1;
var Rows=fileTable.rows; //Rows 数组
var newRow=fileTable.insertRow(fileTable.rows.length); //插入新的一行
var Cells=newRow.cells; //Cells 数组
for (i=0;i<3;i++) //每行的2列数据,一列用来显示文件名,一列显示"删除"操作
{
var newCell=Rows(newRow.rowIndex).insertCell(Cells.length);
newCell.align="center";
switch (i)
{
case 0 : newCell.innerHTML="<td width='40%' align='left'><span id='"+n+"'></span></td>";
break;
case 1 : newCell.innerHTML="<td width='20%' align='left'><a href='javascript:delTableFileRow(\"" +tempRow+ "\",\"" + n + "\")'>删除</a></TD>";
break;
case 2 : newCell.innerHTML="<td width='40%' align='left'> </TD>";
break;
}
}
maxRows+=1;
document.getElementById(n).insertAdjacentText("beforeBegin",fileTextValue);
n++;
num++;
fileCount++;
}
}
function delTableFileRow(rowNum,fileCount)
{
if (fileTable.rows.length >rowNum){
fileTable.deleteRow(rowNum); //删除当前行
}else
fileTable.deleteRow(fileTable.rows.length-1);
document.all("file").removeChild(document.all("a" + fileCount)); //从元素P上删除子结点 a 。(跟删除表格行同步)
fileCount--; //总数 -1
}
function checkfilename(text)
{
var filebefore;
var ary;
var filetextbefore;
var result=true;
if(n>=1)
{
for(i=0;i<n;i++)
{
filebefore=document.all("file["+i+"]").value;
ary=filebefore.split("\\");
filetextbefore=ary[ary.length-1];
if(filetextbefore==text)
{
return false;
break;
}
}
}
return true;
}
</script>
</head><body>
<form>
<table width="100%" border="0">
<tr>
<td height="30">CCIT文件共享 <p id="file"><a href="#" class="addfile" id="a0">
<input id="my" type="file" class="addfile" onchange="addFile()" name="file[0]" />
</a></p></td>
</tr>
<tr>
<td height="30">
<table width="100%" height="100%" border="0">
<tr><td width="40%" align="left"></td><td width="60%" ></td></tr>
<tr>
<td colspan="2">
<table width="100%" border="0" id="fileTable" align="left"></table>
</td>
</tr>
<tr>
<td colspan="2"><a href="">上传</a></td>
</table>
</td>
</tr>
<tr>
<td height="100"> </td>
</tr>
<tr>
<td height="30"> </td>
</tr>
</table>
</form>
<script language="javascript">
var n=0; //初始化数组为0,之后随着变化
var fileCount=1;
var tempRow=0; //动态表格的临时行
var maxRows=0; //动态表格的临时列
var num = 1;
var fileCount=1;
//添加文件的主要方法
function addFile()
{
var str = '<a href="#" class="addfile" id="a' + num +'"><input id="file" type="file" size="50" class="addfile" onchange="addFile()" name="file[' + num + ']" ' + '/></a>';
var fileText;
var ary;
var fileTextValue;
fileText = document.all("file[" + n + "]").value; //获取文件名称
ary = fileText.split("\\");
fileTextValue = ary[ary.length-1];
if(checkfilename(fileTextValue)==false)
{
alert("此文件已经存在");
}
else
{
document.all("a" + n).style.display = "none";//将前一个 P 的子元素设为不可见
document.getElementById('file').insertAdjacentHTML("beforeEnd",str);
tempRow=fileTable.rows.length-1; //fileTable 就是那个动态的 table 的 ID 了
maxRows=tempRow;
tempRow=tempRow+1;
var Rows=fileTable.rows; //Rows 数组
var newRow=fileTable.insertRow(fileTable.rows.length); //插入新的一行
var Cells=newRow.cells; //Cells 数组
for (i=0;i<3;i++) //每行的2列数据,一列用来显示文件名,一列显示"删除"操作
{
var newCell=Rows(newRow.rowIndex).insertCell(Cells.length);
newCell.align="center";
switch (i)
{
case 0 : newCell.innerHTML="<td width='40%' align='left'><span id='"+n+"'></span></td>";
break;
case 1 : newCell.innerHTML="<td width='20%' align='left'><a href='javascript:delTableFileRow(\"" +tempRow+ "\",\"" + n + "\")'>删除</a></TD>";
break;
case 2 : newCell.innerHTML="<td width='40%' align='left'> </TD>";
break;
}
}
maxRows+=1;
document.getElementById(n).insertAdjacentText("beforeBegin",fileTextValue);
n++;
num++;
fileCount++;
}
}
function delTableFileRow(rowNum,fileCount)
{
if (fileTable.rows.length >rowNum){
fileTable.deleteRow(rowNum); //删除当前行
}else
fileTable.deleteRow(fileTable.rows.length-1);
document.all("file").removeChild(document.all("a" + fileCount)); //从元素P上删除子结点 a 。(跟删除表格行同步)
fileCount--; //总数 -1
}
function checkfilename(text)
{
var filebefore;
var ary;
var filetextbefore;
var result=true;
if(n>=1)
{
for(i=0;i<n;i++)
{
filebefore=document.all("file["+i+"]").value;
ary=filebefore.split("\\");
filetextbefore=ary[ary.length-1];
if(filetextbefore==text)
{
return false;
break;
}
}
}
return true;
}
</script>
</head><body>
<form>
<table width="100%" border="0">
<tr>
<td height="30">CCIT文件共享 <p id="file"><a href="#" class="addfile" id="a0">
<input id="my" type="file" class="addfile" onchange="addFile()" name="file[0]" />
</a></p></td>
</tr>
<tr>
<td height="30">
<table width="100%" height="100%" border="0">
<tr><td width="40%" align="left"></td><td width="60%" ></td></tr>
<tr>
<td colspan="2">
<table width="100%" border="0" id="fileTable" align="left"></table>
</td>
</tr>
<tr>
<td colspan="2"><a href="">上传</a></td>
</table>
</td>
</tr>
<tr>
<td height="100"> </td>
</tr>
<tr>
<td height="30"> </td>
</tr>
</table>
</form>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货