new upload

This commit is contained in:
Joe 2016-12-22 23:02:36 +08:00
parent 342c2860b3
commit 7b6f27aebf
1 changed files with 21 additions and 18 deletions

View File

@ -5,13 +5,15 @@ var i = 0; // 用来动态生成span,upfile的id
function addAttachmentToList()
{
if (findAttachment(event.srcElement.value)) return; //如果此文档已在图片列表中则不再添加
if (extractFileName(event.srcElement.value)){
// 动态创建图片信息栏并添加到图片列表中
var span = document.createElement('span');
span.id = '_attachment' + i;
span.innerHTML = extractFileName(event.srcElement.value) + '&nbsp;<a href="javascript:delAttachment(' + (i++) + ')"><font color="blue">删除</font></a><br/>';
span.title = event.srcElement.value;
G('attachmentList').appendChild(span);
}
// 显示图片列表并变换添加图片按钮文本
if (G('attachmentList').style.display == 'none')
@ -34,11 +36,19 @@ function selectAttachment()
document.body.insertAdjacentHTML('beforeEnd', upfile);
G('_upfile'+i).click();
}
//判断图片格式
function extractFileName(fn)
{
var index = fn.substr(fn.lastIndexOf('.')).toLowerCase();
if (index ==".png"||index ==".jpg"||index ==".jpeg"){
return fn.substr(fn.lastIndexOf('\\')+1);
}
else{
alert("请上传png或jpg格式的图片");
return 0;
}
}
function findAttachment(fn)
{
@ -92,13 +102,6 @@ function clearAttachment()
G('attachmentList').style.display = 'none';
G('btnClear').style.display = 'none';
G('total').innerText = '当前选择上传0个图片';
}
function getAttachmentInfo()
{
// 已知的js获取本地文件大小的三种方式
}
function G(id)