[英]File input field inside button doesn't work in Firefox
我想在我的頁面上有一個樣式文件input
字段,因此將其放在一個完全覆蓋的button
,並通過將其opactiy設置為0使其不可見。
這種方法在最新版本的Chrome中運行良好,但Firefox(和IE)在單擊按鈕時不會打開文件對話框:
http://jsfiddle.net/ch8xxvez/3/
<button style="width: 100px; height: 100px; position: relative;">Upload button
<input type="file" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0;"></input>
</button>
如果我用div
替換button
元素,相同的代碼可以工作,但我真的想知道是否有一種方法可以使用最新版本的IE(> = 10),FF,Chrome&中的button
標記。邊緣。
HTML中的按鈕元素內不允許輸入元素。
編寫有效的HTML而不是依賴於一致的錯誤恢復。
制作按鈕並輸入同級元素,然后將它們放在容器(例如div)中。
試試吧
https://jsfiddle.net/DeivissonSedrez/0z6mq5yk/1/
<div class="fakeButton">Upload button
<input type="file" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0;"></input>
</div>
<style>
.fakeButton{
width: 100px;
height: 100px;
position: relative;
border:1px solid #000;
border-radius:3px;
text-align:center;
font: 15px arial;
line-height:90px;
box-shadow: inset 0 2px 3px 0 rgba(255,255,255,.3), inset 0 -3px 6px 0 rgba(0,0,0,.2), 0 3px 2px 0 rgba(0,0,0,.2);
background-image: -webkit-linear-gradient(#EEEEEE, #D8D8D8 130%);
background-image: -moz-linear-gradient(#EEEEEE, #D8D8D8 130%);
background-image: -o-linear-gradient(#EEEEEE, #D8D8D8 130%);
background-image: linear-gradient(#EEEEEE, #D8D8D8 130%);
}
</style>
我將輸入放在div中,並使div看起來像一個帶css的按鈕
他們在我的IE,FF和Chrome測試中工作
我希望它有所幫助
在<button>
有<input>
無效。 考慮將其放在<label>
,或者使用單擊處理程序和合適的CSS或使用錨標記將<span>
放入其中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.