一个简单的上传附件,并显示附件的方法.(JS的DOM操作取得input file的值.)

 
  1.     function addAttachment()
  2.         ...{
  3.             var strAttachPathArray;
  4.             var strFileName="";
  5.             var strAttachPath=""//the path of the file...
  6.             var attach = "";
  7.             var attachDIV = this.document.getElementById("attachmentList"); //this div will save the attachment
  8.             for(var i=0;i<document.forms[0].elements.length;i++) //loop the whole form
  9.             ...{
  10.                 if(document.forms[0].elements[i].type=="file"//find if it is a <input type="file" elements
  11.                 ...{
  12.                     if(document.forms[0].elements[i].value != ""//this is not a empty path.
  13.                     ...{
  14.                         strAttachPath = document.forms[0].elements[i].value; //get this path
  15.                         strPathArray = strAttachPath.split("//");//separate this string as a array depends on "/". / needs convert.
  16.                         strFileName = strPathArray[strPathArray.length-1]; //get the file name,if you can not understand please debug and search by your self
  17.                         attach = attach + "<img src='images/attachment.GIF' border='0' />" + strFileName + "  ";
  18.                         //img is a pic....
  19.                     }
  20.                 }
  21.             }
  22.             attachDIV.innerHTML = attach;
  23.         }
  24.  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值