日期:2014-05-16  浏览次数:20487 次

多附件上传的问题,仿163,强人看下

<script       language= "javascript ">      
        //动态文件记数器
var   num=0;
//div内容
var   divstr= " ";
//添加的文件名数组
var   filename=new   Array();
function       File1_onchange()       {      
//判断添加文件是否重复
var   pathfile   =   document.PostForm.File1.value;
//alert( "infilepathandname   =   "+pathfile);
var   name   =   pathfile.substring(pathfile.lastIndexOf( '\\ ')+1);
//alert( "infilename   =   "+name);

if(checkAgainFile(name)){
alert( "该文件已经添加! ");
return   false;
}

if(checkFileNum(name)){
alert( "最大文件不能超过5 ");
return   false;
}

//先+file控件
addFile();
//把File1取得的值赋给新添加的file控件上
document.getElementsByName( 'uploadFiles '+num).value=document.PostForm.File1.value   ;      
alert(document.getElementsByName( 'uploadFiles '+num).value);
//表层的表示
adddiv();

//for(var   i=0;i <num;i++){
//var   t=i+1;
//alert(document.getElementsByName( 'uploadFiles '+t).value);
//}

/*
for(var   i=0;i <num;i++){
var   t=i+1;
alert(document.getElementsByName( 'uploadFiles '+t).value);
}

for(var   i=0;i <filename.length;i++){
alert( "filenames= "+filename[i]);
}
*/
//document.PostForm.File1.select();
//document.execCommand( 'delete ');  
}      

//添加层内容
function   adddiv(){
var   obj=document.getElementById( "showFile ");
var   fileStr   =document.getElementsByName( 'uploadFiles '+num).value;
var   fileName   =   fileStr.substring(fileStr.lastIndexOf( '\\ ')+1);
//增加数组内容
filename[filename.length]=fileName;
var   addStr= " <a   href= 'javascript:DelFile( "+num+ ") '> <img   src= 'image/attach.gif '   alt= '删除 '   /> </a> "+ "; ";
divstr=divstr+fileName+addStr   ;  
obj.innerHTML=divstr;
}
//减少层内容
function   deldiv(delno){
//var   str   =   "This   is   a   string ";
//alert(str.substring(1,   3));   //结果为hi  
//alert(str.substring(3,   1));   //结果为hi  
//alert(str.substring(0,   4));   //结果为This  
//alert(str.substring(8));   //结果为a   string

var   newDivStr   = " ";
var   a=new   Array();

divstr=divstr.substring(0,divstr.lastIndexOf( '; '));

a=divstr.split( "; ");

var   del=(new   Number(delno));
for(var   i=0;i <a.length;i++){
if(i!=del)
newDivStr=newDivStr+a[i]+ "; ";

}
divstr=newDivStr;
}
 
//增加file控件
function   addFile(){
var   tableobj=document.getElementById( 'table1 ');
var   Row1=tableobj.insertRow(tableobj.rows.length);
//rows就是行数的集合,tableobj.rows.length是获得表格的行数
var   Rows=tableobj.rows;
//cells是表元,就是 <td> </td>
var   Cells=Row1.cells;
var   Cell1=Rows(Row1.rowIndex).insertCell();
Cell1.align= "left ";  
Cell1.innerHTML= " <input