我想做一個像亞馬遜一樣的檔案輸入按鈕寫下圖所示的評論

如果輸入檔案型別被隱藏,整個按鈕怎么可能在單擊時打開檔案對話框?

我的代碼在這里隱藏了輸入檔案型別按鈕,但沒有打開檔案對話框。它使用帶有順風類的 React
<button
type="button"
className="p-6"
>
<div aria-label="Add a photo">
<HiOutlinePlus className="text-4xl" />
<input type="file" accept="image/*" className="hidden" />
</div>
</button>
uj5u.com熱心網友回復:
如果輸入檔案型別被隱藏,整個按鈕怎么可能在單擊時打開檔案對話框?
可能使用單獨的小部件,然后在單擊時打開隱藏檔案輸入,如下所示:
function openFileUpload() {
document.getElementById("hiddenFile").click();
}
<button onclick="openFileUpload()" type="button">Visible Button</button>
<input type="file" id="hiddenFile" style="visibility:hidden">
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/458895.html
標籤:javascript 反应 文件 顺风CSS
