Posted on 2007-08-01 08:50
semovy 閱讀(1055)
評論(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>