仿QQ邮箱附件,这个只能看不能用。原因忘记了,反正跟IE有关。
<!--
Author: aqua qin
Tech blog:http://blog.csdn.net/aquadp/
Create Date: 2008-4-8 22:00:00
Last Modify Date: 2008-4-9 22:46:35
-->
<HTML>
<HEAD>
<script>
/**//*
需要注意的几个地方:
.由于input type=file控件不能对type属性赋值(in IE),所以采用插入HTML代码的方式(insertAdjacentHTML);
.input type=file控件的value是只读的,不能被赋值;
.因为用一个input type=file控件有缺陷,就是当用户删除了最后一次添加的文件再添加同样的文件则无法触发onchange事件;
并且要上传文件,只用一个上传控件是不够的;
.客户端无法获取文件大小,除非用FSO或ActiveX等。除了img控件,其fileSize可以在图片文件加载完成后获取其文件大小;
.还有另外一种变通的方法就是用flash与js交互达到获取客户端文件大小的效果(现在flash在安全方面也做了限制);
*/
var i = 0; // 用来动态生成span,upfile的id
function addAttachmentToList()
{
if (findAttachment(event.srcElement.value)) return; //如果此文档已在附件列表中则不再添加
// 动态创建附件信息栏并添加到附件列表中
var span = document.createElement('span');
span.id = '_attachment' + i;
span.innerHTML = extractFileName(event.srcElement.value) + ' <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')
{
G('btnAdd').value = '继续添加';
G('attachmentList').style.display = '';
G('btnClear').style.display = '';
}
G('total').innerText = '当前选择上传'+ G('attachmentList').childNodes.length + '个附件';
}
function selectAttachment()
{
// 先清除无效动态生成的多余upfile
cleanInvalidUpfile();
// 动态创建上传控件并与span对应
var upfile = '<input type="file" style="display:none" onchange="addAttachmentToList();" id="_upfile'+i+'">';
document.body.insertAdjacentHTML('beforeEnd', upfile);
G('_upfile'+i).click();
}
function extractFileName(fn)
{
return fn.substr(fn.lastIndexOf('\\')+1);
}
function findAttachment(fn)
{
var o = G('attachmentList').getElementsByTagName('span');
for(var i=0;i<o.length;i++)
if (o[i].title == fn) return true;
return false;
}
function delAttachment(id)
{
G('attachmentList').removeChild(G('_attachment'+id));
document.body.removeChild(G('_upfile'+id));
// 当附件列表为空则不显示并且变化添加附件按钮文本
if (G('attachmentList').childNodes.length == 0)
{
G('btnAdd').value = '添加附件';
G('attachmentList').style.display = 'none';
G('btnClear').style.display = 'none';
}
G('total').innerText = '当前选择上传'+ G('attachmentList').childNodes.length + '个附件';
}
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)))
document.body.removeChild(o[i]);
}
}
function clearAttachment()
{
var o = G('attachmentList').childNodes;
for(var i=o.length-1;i>=0;i--)
G('attachmentList').removeChild(o[i]);
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)
{
document.body.removeChild(o[i]);
}
G('btnAdd').value = '添加附件';
G('attachmentList').style.display = 'none';
G('btnClear').style.display = 'none';
G('total').innerText = '当前选择上传0个附件';
}
function getAttachmentInfo()
{
// 已知的js获取本地文件大小的三种方式
// 1.通过FSO 2.通过ActiveX 3.通过Flash(设置可能更麻烦)与js交互
// 注:QQ邮箱中获取本地文件大小就是采用第二种方式
}
function G(id)
{
return document.getElementById(id);
}
</script>
</HEAD>
<BODY>
<fieldset style="border : 1px solid #84A24A;text-align:left;COLOR:#84A24A;FONT-SIZE:
12px;font-family: Verdana;padding:5px;">
<legend>模仿QQ邮箱添加附件</legend>
<input style="background:transparent;border:1px solid #84A24A;color:#84A24A" type="button" value="添加附件" id="btnAdd" onclick="selectAttachment();"> <input type="button" value="清空附件" style="background:transparent;border:1px solid #84A24A;color:#84A24A" id="btnClear" style="display:none" onclick="clearAttachment();">
<div id="attachmentList" style="margin:3px 0px 0px 0px;padding:4px 3px 4px 3px;background-color:#DEEBC6;display:none;border:1px solid #84A24A;">
</div>
<div id="total" style="margin:3px 0px 0px 0px;">当前选择上传0个附件</div>
</fieldset>
</BODY>
</HTML>
分享到:
相关推荐
C# 完美获取QQ邮箱 网易邮箱邮件及附件
模仿QQ邮箱的大文件上传功能,带进度条,源代码,可自行修改,基于swfupload制作
一个简单的android邮箱,仿QQ邮箱的,有邮件的收发,附件的保存等功能,代码比较少,看的简单,我等下会传一个更完成的邮箱,仿网易的,看完这个可以下载另一个。
下载QQ邮件附件并将其标为已读C#源码, 只限QQ邮箱,SINA和163由于服务器限制,不可用,在VS下测试可用
类似qq邮箱附件上传功能,选择文件逐条自定上传,删除等,后台java
可以实现qq邮箱发送多人邮件,邮件可配置模板,邮件可以附带附件,附件的获取方式采用文件流方式
批量下载QQ邮箱中的所有附件 procedure TFrm_QQMailRev.bt_revClick(Sender: TObject); var i,j,fNum,fCount : integer; tmp, fName : string; begin bt_rev.Enabled := false; IdMessage1.CharSet := 'gb2312';...
qq邮箱附件下载办法,遇到不能下载的情况时,就可以用这种方法
用Delphi2010 实现邮件附件收发功能 TIdPOP3组件简介 TIdPOP3 是用来接收邮件服务器的邮件信息到用户端的一个组件。它实现了RFC 1939协议。 在使用TIdPOP3组件时需设置它的几个成员属性。 Host :指定邮件服务器,...
类似QQ邮箱的js附件上传源代码,对于学习来讲还是不错的。
邮件的大附件,有时无法下载,有时速度慢时间长.QQ旋风提供较好的解决办法。
MailKit 邮件发送附件下载,包含BouncyCastle.dll,MailKit.dll,MimeKit.dll,vs2012示例工程MailKitConsoleApplication示例代码邮件附件下载,发送邮件,需要.netframework 4.5。
C# 邮箱附件下载,下载后删除邮件
php发送邮件功能(qq授权可传递附件功能)内容有qq协议设置图解,相关数据的备注说明
java发送qq邮件 支持群发 附件等等等..
本文实例为大家分享了python3通过qq邮箱发送邮件以及附件的具体代码,供大家参考,具体内容如下 开启qq邮箱的smtp服务 代码: import smtplib from email.mime.text import MIMEText from email.mime.multipart ...
QQ邮箱附件预览功能评测.docx
通过Java读取QQ邮件及邮件解析-附件资源
压缩包内包含工具代码(实现方式注释在开头^_^),3个依赖jar包
Python实现邮箱(以QQ邮箱为例)自动化处理,包括自动发送、读取、删除、定时发送等等 目录 1 模块介绍与安装 2 利用Python发送邮件 2.1 发送一封简单的电子邮件 2.2 发送含HTML样式的电子邮件 2.3 发送带附件的...