diff --git a/多图片上传.html b/多图片上传.html
index ced6a44..24fd16d 100644
--- a/多图片上传.html
+++ b/多图片上传.html
@@ -4,7 +4,12 @@
var pic_num = 0,pic_maxnum = 5; // 用来动态生成span,upfile的id,一次上传图片数量接口
function addAttachmentToList()
{
- if (findAttachment(event.srcElement.value)) return; //如果此文档已在图片列表中则不再添加
+ if (findAttachment(event.srcElement.value)){
+ var o = G('pics').getElementsByTagName('input');
+ var len = o.length-1;
+ G('pics').removeChild(o[len]);
+ return;
+ }; //如果此文档已在图片列表中则不再添加
if (extractFileName(event.srcElement.value)){
// 动态创建图片信息栏并添加到图片列表中
var span = document.createElement('span');
@@ -28,15 +33,16 @@ function addAttachmentToList()
function selectAttachment()
{
+
// 先清除无效动态生成的多余upfile
- cleanInvalidUpfile();
- if(pic_num < pic_maxnum) {//图片数量控制接口
+ cleanInvalidUpfile();
+ if(pic_num < pic_maxnum ) {//图片数量控制
var upfile = '';// 动态创建上传控件并与span对应
G('pics').insertAdjacentHTML('beforeEnd', upfile);
G('_upfile'+pic_num).click();
- }
- else alert("一次只能上传"+pic_maxnum+"张图片!");
-
+ }
+ else alert("一次只能上传"+pic_maxnum+"张图片!");
+
}
//判断图片格式
function extractFileName(fn)
@@ -78,13 +84,15 @@ function delAttachment(id)
function cleanInvalidUpfile()
{
- var o = document.body.getElementsByTagName('input');
- for(var i=o.length-1;i>=0;i--)
- if (o[i].type == 'file' && o[i].id.indexOf('_upfile') == 0)
- {
- if (!G('_attachment'+o[i].id.substr(7)))
- G('pics').removeChild(o[i]);
- }
+ var o = G('pics').getElementsByTagName('input');
+ var len = o.length-1;
+ for(var i=o.len;i>=0;i--){
+ if (o[i].type == 'file' && o[i].id.indexOf('_upfile') == 0)
+ {
+ if (!G('_attachment'+o[i].id.substr(7)))
+ G('pics').removeChild(o[i]);
+ }
+ }
}
function clearAttachment()