<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>简便无刷新文件上传系统</title>
<script src="CJL.0.1.min.js"></script>
<script src="QuickUpload.js"></script>
</head>
<body>
<style>
.upload {width:600px;background:#fff;font-size:12px; border-collapse:collapse;}
.upload td, .upload th {padding:5px;border:1px solid #ebebeb;}
.upload thead td {background-color:#ebebeb;}
.upload th { text-align:center;}
.upload b {font-size:14px;}
.upload tbody td{ height:30px;}
.upload tfoot td{ word-spacing:20px;}
.upload a:link, .upload a:visited, .upload a:hover, .upload a:active {color:#00F;}
</style>
<form action="Files.asp" method="post" enctype="multipart/form-data">
<table border="0" class="upload">
<thead>
<tr>
<td colspan="4"><b>文件上传</b></td>
</tr>
<tr>
<th>选择文件</th>
<th width="25%">重命名</th>
<th width="15%">操作</th>
<th width="15%">状态</th>
</tr>
</thead>
<tbody id="idTable">
<tr>
<td><input name="file" type="file" />
<span></span></td>
<td><input size="15" name="title" type="text" />
<span></span></td>
<td align="center"><a href="?">重置</a></td>
<td align="center"><span>选择文件</span></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4" align="center"><script>
document.writeln("<input id=\"idAdd\" type=\"button\" value=\"添加文件\">")
document.writeln("<input id=\"idQuick\" type=\"button\" value=\"极速上传\">")
</script>
<input id="idNormal" type="submit" value="一般上传"></td>
</tr>
</tfoot>
</table>
</form>
<br>
<a href="http://www.cnblogs.com/cloudgamer/">如有任何疑问或建议欢迎来我的博客交流</a>
<script>
var qus = [], count = 0, table = $$("idTable"), model = table.rows[0];
table.removeChild(model);
function add(){
var row = model.cloneNode(true),
inputs = row.getElementsByTagName("input"),
file = inputs[0], title = inputs[1],
spans = row.getElementsByTagName("span"),
msgfile = spans[0], msgtitle = spans[1], msg = spans[2],
a = row.getElementsByTagName("a")[0],
qu = new QuickUpload(file, {
action: "Files.asp",
timeout: 6,
onReady: function(){
count++;
show("上传中..");
a.innerHTML = "停止"; a.onclick = function(){ qu.stop(); return false; };
//设置表单
this.parameter.title = title.value;
file.style.display = title.style.display = "none";
msgfile.innerHTML = file.value; msgtitle.innerHTML = title.value;
},
onFinish: function(iframe){
try{//处理返回信息(需要后台配合)
var info = eval("(" + iframe.contentWindow.document.body.innerHTML + ")");
show("上传完成");
}catch(e){//获取数据出错
show("上传失败"); stop(); return;
}
count--; CheckBtn();
row.cells[0].innerHTML = "<a href=\"" + info.path + "\" target='_blank'>" + info.name + "</a>";
row.cells[1].innerHTML = info.name;
a.innerHTML = "下载"; a.href = info.path; a.onclick = null;
//移除程序
this.remove();
},
onStop: function(){ show("已经停止"); stop(); },
onTimeout: function(){ show("上传超时"); stop(); }
});
a.onclick = reset
function stop(){
count--; CheckBtn();
a.innerHTML = "重置"; a.onclick = reset;
file.style.display = msgfile.innerHTML =
title.style.display = msgtitle.innerHTML = "";
}
function reset(){ show("选择文件"); ResetFile(file); return false; }
function show(m){ msg.innerHTML = m; }
file.onchange = function(){ show(this.value ? "准备上传" : "选择文件"); }
qus.push(qu);
table.appendChild(row);
}
add();
add();
add();
$$("idAdd").onclick = function(){
qus.length >= 6 ? alert("不要太贪心啦") : add();
}
$$("idQuick").onclick = function(){
$$A.filter(qus, function(qu){ qu.upload(); }); CheckBtn();
}
function CheckBtn(){
$$("idNormal").disabled = $$("idQuick").disabled = !!count;
}
function ResetFile(file){
file.value = "";//ff chrome safari
if ( file.value ) {
if ( $$B.ie ) {//ie
with(file.parentNode.insertBefore(document.createElement('form'), file)){
appendChild(file); reset(); removeNode(false);
}
} else {//opera
file.type = "text"; file.type = "file";
}
}
}
</script>
</body>
</html>