Posted on 2007-08-01 08:50
semovy 阅读(1053)
评论(0) 编辑 收藏 所属分类:
JavaScript
表格对象的insertRow和insertCell方法有一个默认的参数-1,表示在当前行或者单元格后插入行和单元格。在ie中可以不用填写这个参数,但是在firefox浏览器下必须加上这个参数否则就会出现缺少参数的错误。
<html>
<head>
<title>
multiUploadDemo
</title>
</head>
<script language="javascript">
var num = 0;
function upload(){
document.getElementById("status").innerHTML = "文件上传中...";
multiUploadForm.submit();
}
function additem(id)
{
var row,cell,str;
//row = eval("document.all["+'"'+id+'"'+"]").insertRow();
row = document.getElementById(id).insertRow(-1);
if(row != null )
{
cell = row.insertCell(-1);
str="<input type="+'"'+"file"+'"'+" name=uploadFile["+ num +"].file><input type="+'"'+"button"+'"'+" value="+'"'+"删除"+'"'+" onclick='deleteitem(this,"+'"'+"tb"+'"'+");'>"
cell.innerHTML=str;
}
num++;
}
function deleteitem(obj,id)
{
var rowNum,curRow;
curRow = obj.parentNode.parentNode;
//rowNum = eval("document.all."+id).rows.length - 1;
rowNum = document.getElementById(id).rows.length - 1;
document.getElementById(id).deleteRow(curRow.rowIndex);
//eval("document.all["+'"'+id+'"'+"]").deleteRow(curRow.rowIndex);
}
function callback(msg)
{
document.getElementById("status").innerHTML = "文件上传完成...<br>" + msg;
}
</script>
<body bgcolor="#ffffff">
<div id="status"></div>
<html:form method="post" action="/multiUpload.do" enctype="multipart/form-data" target="hidden_frame">
<table id="tb">
</table>
</html:form>
<iframe name='hidden_frame' id="hidden_frame" style="display:none"></iframe>
<input type="button" name="btnAddFile" value="Add File" onclick="additem('tb')"/>
<input type="button" name="btnUpload" value="upload" onclick="upload()"/>
</body>
</html>