2012-06-09 48 views
0

我用下面的代碼進行定製文件輸入型不顯示,上傳的文件名中的自定義文件輸入

<form class="example" action="#"> 
<!--<input type="file" class="required-entry filename file" name="filename[]" />--> 
<div class="fileinputs"> 
    <input type="file" class="file hidden"> 
<div class="fakefile"><input><img src="ravi/images/button_select.gif" /></div></div> 
</form> 

的style.css

<style type="text/css"> 
    body{ 
     color: black; 
     font-family: arial; 
     font-size: 13px; 
    } 
form.example input { 
    background: url('ravi/images/input_boxes.gif') no-repeat 0 -58px; 
    border: none; 
    width: 241px; 
    height: 20px; 
    padding-left: 3px; 
    padding-top: 3px; 
} 

form.example input:focus { 
    background-color: transparent; 
} 

form.example div.fileinputs { 
    position: relative; 
    height: 30px; 
    width: 300px; 
} 

form.example input.file { 
    width: 300px; 
    margin: 0; 
} 

form.example input.file.hidden { 
    position: relative; 
    text-align: right; 
    -moz-opacity:0 ; 
    filter:alpha(opacity: 0); 
    opacity: 0; 
    z-index: 2; 
} 

form.example div.fakefile { 
    position: absolute; 
    top: 0px; 
    left: 0px; 
    width: 350px; 
    padding: 0; 
    margin: 0; 
    z-index: 1; 
    line-height: 90%; 
} 

form.example div.fakefile input { 
    margin-bottom: 5px; 
    margin-left: 0; 
} 

</style> 

和頁面顯示如下圖所示,

enter image description here

當我點擊選擇按鈕瀏覽文件夾中出現,然後我選擇在輸入圖像file.but提起不顯示上傳的圖片的標題..

我綜合這一個從http://www.quirksmode.org/dom/inputfile.html

問題是什麼?

回答

0

您需要添加JavaScript代碼,你引用的頁面上解釋。

如果您在測試中使用的代碼基本的,你貼出來,那麼你正在使用的頁面上所描述的方法的「純CSS」版本的HTML和CSS代碼組成。在編號列表,解釋了基本的版本,它也使用JavaScript,第5項描述了從「純CSS」版缺少的功能。而這功能是「當用戶選擇了一個文件,可見,假輸入框顯示正確的此文件路徑」。

(它實際上不會顯示正確的路徑。出於安全考慮,瀏覽器不透露真實路徑。但是,他們讓你展現一部分。)