new upload
This commit is contained in:
parent
342c2860b3
commit
7b6f27aebf
39
多图片上传.html
39
多图片上传.html
|
@ -5,13 +5,15 @@ var i = 0; // 用来动态生成span,upfile的id
|
||||||
function addAttachmentToList()
|
function addAttachmentToList()
|
||||||
{
|
{
|
||||||
if (findAttachment(event.srcElement.value)) return; //如果此文档已在图片列表中则不再添加
|
if (findAttachment(event.srcElement.value)) return; //如果此文档已在图片列表中则不再添加
|
||||||
|
if (extractFileName(event.srcElement.value)){
|
||||||
// 动态创建图片信息栏并添加到图片列表中
|
// 动态创建图片信息栏并添加到图片列表中
|
||||||
var span = document.createElement('span');
|
var span = document.createElement('span');
|
||||||
span.id = '_attachment' + i;
|
span.id = '_attachment' + i;
|
||||||
span.innerHTML = extractFileName(event.srcElement.value) + ' <a href="javascript:delAttachment(' + (i++) + ')"><font color="blue">删除</font></a><br/>';
|
span.innerHTML = extractFileName(event.srcElement.value) + ' <a href="javascript:delAttachment(' + (i++) + ')"><font color="blue">删除</font></a><br/>';
|
||||||
span.title = event.srcElement.value;
|
span.title = event.srcElement.value;
|
||||||
G('attachmentList').appendChild(span);
|
G('attachmentList').appendChild(span);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 显示图片列表并变换添加图片按钮文本
|
// 显示图片列表并变换添加图片按钮文本
|
||||||
if (G('attachmentList').style.display == 'none')
|
if (G('attachmentList').style.display == 'none')
|
||||||
|
@ -34,10 +36,18 @@ function selectAttachment()
|
||||||
document.body.insertAdjacentHTML('beforeEnd', upfile);
|
document.body.insertAdjacentHTML('beforeEnd', upfile);
|
||||||
G('_upfile'+i).click();
|
G('_upfile'+i).click();
|
||||||
}
|
}
|
||||||
|
//判断图片格式
|
||||||
function extractFileName(fn)
|
function extractFileName(fn)
|
||||||
{
|
{
|
||||||
return fn.substr(fn.lastIndexOf('\\')+1);
|
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)
|
function findAttachment(fn)
|
||||||
|
@ -91,16 +101,9 @@ function clearAttachment()
|
||||||
G('btnAdd').value = '添加图片';
|
G('btnAdd').value = '添加图片';
|
||||||
G('attachmentList').style.display = 'none';
|
G('attachmentList').style.display = 'none';
|
||||||
G('btnClear').style.display = 'none';
|
G('btnClear').style.display = 'none';
|
||||||
G('total').innerText = '当前选择上传0个图片';
|
G('total').innerText = '当前选择上传0个图片';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAttachmentInfo()
|
|
||||||
{
|
|
||||||
// 已知的js获取本地文件大小的三种方式
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function G(id)
|
function G(id)
|
||||||
{
|
{
|
||||||
return document.getElementById(id);
|
return document.getElementById(id);
|
||||||
|
|
Loading…
Reference in New Issue