2011-08-25 60 views

回答

6

編輯:正如其他人指出Firefox不suuport下面的方法我會參考以下鏈接http://www.quirksmode.org/dom/inputfile.html

下面是一個非常簡單的解決方案。我會建議添加一個類到標籤雖然。基本上,你的風格標籤,而不是輸入的避免了跨瀏覽器的問題,寬度和高度的錯誤:

<label> 
    <input type=file> 
</label> 

CSS

label input{-moz-opacity:0 ;filter:alpha(opacity: 0);opacity: 0;} 
label {background:green;width:200px;height:100px;display:block; /* more styles here */} 

http://jsfiddle.net/DVLxp/

+0

這完美的作品。我結束了調整我的形象,以適應上傳按鈕的大小使用另一個例子,但是這太棒了!非常簡單! – Fostah

+5

在Firefox中,您無法單擊文件輸入標籤 – Znarkus

+0

在Firefox中,整個綠色區域不可點擊,並且不顯示指針。 – chovy

2

什麼時,他們需要一個「定製化」的網站經常做文件上傳小部件:隱藏「真實」文件上傳字段。添加一個文本字段,該字段將顯示文件上傳字段的當前值以及一個將在文件上傳字段中觸發文件選擇的按鈕。下面一個例子:

<input id="file" type="file" style="display: none;" 
     onchange="document.getElementById('text').value = this.value;"> 

<input id="text" type="text" readonly><input type="button" 
     onclick="document.getElementById('file').click();" value="Choose file"> 
+0

+1這對我來說非常合適,似乎是最簡單的快速解決方案。謝謝 – jnthnjns

1

至於我,振亞舍甫琴科給了最好的工作解決方案之一。用他的方法,我們可以創建跨瀏覽器的文件輸入按鈕:http://jsfiddle.net/JHcFR/

<div class="fileInput"> 
    <input type="file" /> 
</div> 

.fileInput { 
    overflow: hidden; width: 500px; height: 200px; background: red; 
} 
.fileInput input { 
    font-size: 200px; opacity: 0; 
    float: right; filter: alpha(opacity=0); /*IE*/ 
} 
3

試試這個:http://jsfiddle.net/CnHj5/ 在Firefox和一個不錯的指針光標是可用的。

HTML:

<div class="upload"> 
    <input class="upload" type="file" /> 
</div> 

CSS:

input.upload { 
    -moz-opacity:0; 
    filter:alpha(opacity: 0); 
    opacity: 0; 
    position: absolute; 
    right:0; 
    font-size: 200px; 
    cursor: pointer; 
} 
div.upload { 
    background-color:green; 
    width:200px; 
    height:100px; 
    position: relative; 
    display:block; 
    overflow:hidden;} 
相關問題