//var FileUploader=new Object();var TotalFiles = 0;
//FileUploader.AddFiles=function ()function AddFiles()
{
TotalFiles ++;
var file=document.createElement("input");
file.type = "file";
file.id = "f"+ TotalFiles.toString();
file.name = "files"+ TotalFiles.toString();
file.hideFocus = true;
file.style.cssText = "cursor:pointer; width:1px; border:none;height:32px; padding:0px; margin:0px;position:absolute; opacity:0;filter:alpha(opacity=100);font-size:20px;";
file.onchange = function ()
{
for (var i=1;i<=TotalFiles;i++)
{
if ($("f"+i.toString())&&$("f"+i.toString())!=this)
{
if ($("f"+i.toString()).value == this.value)
{
DelFile(this.id.replace("f",""));
AddFiles();
window.alert("已有相同文件,不需重複上傳");
return;
}
}
}
$("s"+TotalFiles.toString()).innerHTML = $("f"+TotalFiles.toString()).value.substring($("f"+TotalFiles.toString()).value.lastIndexOf("\\")+1,$("f"+TotalFiles.toString()).value.length) + "<span onclick=\"DelFile('"+TotalFiles.toString()+"')\" style=\"cursor:pointer;color:red\"><img src='img/icon_attdel.gif'/></span>";
this.style.display = "none";
AddFiles();
};
$("UpFilePanelHidden").appendChild(file);
var div=document.createElement("div");
div.id = "s"+ TotalFiles.toString();
$("UpFilePanelShow").appendChild(div);}function $(str)
{
return document.getElementById(str);
}function DelFile(str)
{
$("UpFilePanelHidden").removeChild($("f"+str));
$("UpFilePanelShow").removeChild($("s"+str));
}
function DelEmpty()
{
for (var i=1;i<=TotalFiles;i++)
{
if ($("f"+i.toString()))
{
if ($("f"+i.toString()).value == "")
$("UpFilePanelHidden").removeChild($("f"+i.toString()));
}
}
}调用的网页代码如下:
......
<div style="width:100px; height:30px;background-image:url(img/all_toolbar.gif);background-position:2px -64px; margin:6px 4px; border:1px solid #bebebe; cursor:pointer; "></div>
<a id="UpFilePanelHidden" href="javascript:void(0)"></a>
<script language="javascript">AddFiles();</script>
......
//FileUploader.AddFiles=function ()function AddFiles()
{
TotalFiles ++;
var file=document.createElement("input");
file.type = "file";
file.id = "f"+ TotalFiles.toString();
file.name = "files"+ TotalFiles.toString();
file.hideFocus = true;
file.style.cssText = "cursor:pointer; width:1px; border:none;height:32px; padding:0px; margin:0px;position:absolute; opacity:0;filter:alpha(opacity=100);font-size:20px;";
file.onchange = function ()
{
for (var i=1;i<=TotalFiles;i++)
{
if ($("f"+i.toString())&&$("f"+i.toString())!=this)
{
if ($("f"+i.toString()).value == this.value)
{
DelFile(this.id.replace("f",""));
AddFiles();
window.alert("已有相同文件,不需重複上傳");
return;
}
}
}
$("s"+TotalFiles.toString()).innerHTML = $("f"+TotalFiles.toString()).value.substring($("f"+TotalFiles.toString()).value.lastIndexOf("\\")+1,$("f"+TotalFiles.toString()).value.length) + "<span onclick=\"DelFile('"+TotalFiles.toString()+"')\" style=\"cursor:pointer;color:red\"><img src='img/icon_attdel.gif'/></span>";
this.style.display = "none";
AddFiles();
};
$("UpFilePanelHidden").appendChild(file);
var div=document.createElement("div");
div.id = "s"+ TotalFiles.toString();
$("UpFilePanelShow").appendChild(div);}function $(str)
{
return document.getElementById(str);
}function DelFile(str)
{
$("UpFilePanelHidden").removeChild($("f"+str));
$("UpFilePanelShow").removeChild($("s"+str));
}
function DelEmpty()
{
for (var i=1;i<=TotalFiles;i++)
{
if ($("f"+i.toString()))
{
if ($("f"+i.toString()).value == "")
$("UpFilePanelHidden").removeChild($("f"+i.toString()));
}
}
}调用的网页代码如下:
......
<div style="width:100px; height:30px;background-image:url(img/all_toolbar.gif);background-position:2px -64px; margin:6px 4px; border:1px solid #bebebe; cursor:pointer; "></div>
<a id="UpFilePanelHidden" href="javascript:void(0)"></a>
<script language="javascript">AddFiles();</script>
......
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货