還有一個問題就是,如何利用這一個控件,進行多個文檔的上傳工作?
利用dom操作,當每次選擇了一個文件的時候,隱藏該file域,在相同位置創建一個新的供下次點擊,刪除的時候只要直接刪掉隱藏的就行了[初步想法未經證實]
一直以來上傳控件input file都無法進行美化,例如換個圖片什么的;查了很多資料最終就是需要利用隱藏file域實現上傳功能;其實很簡單,從163里面找了一個樣式出來,搞定;
js代碼: //依賴prototype.js
function selfile()
{
$("fileurl").value = $("file").value;
}
css代碼://來自mail.163.com
a.addfile{width:70px;height:20px;position:relative;cursor:hand;top:4px;top/**/:0;text-decoration:none;background-position:-823px -17px;display:inline;float:left;margin-top:-5px;margin-top/**/:-1px}
*:lang(zh) a.addfile{margin-top:-2px;cursor:pointer}
a.addfile:hover{background-position:-911px -17px;text-decoration:none}
input.addfile{width:1px;height:18px;cursor:pointer!important;cursor:hand;position:absolute;top:5px;left:-5px;left/**/:-3px;opacity:0;filter:alpha(opacity=0)}
*:lang(zh) input.addfile{left:-18px}
html代碼://
<input type="text" value="" id="fileurl" name="fileurl" readonly/>
<a href="#" class="addfile"> <input type="file" name="file" id="file" hideFocus class="addfile" onChange="selfile();"/>+添加附件(也可以放個美化的圖片) </a>