JS觸發file類型Input的onclick()

之因此要作這件事,是爲了作一個好看的上傳按鈕。code

而後把文件input給隱藏了,經過這個自定義的按鈕來呼出上傳窗口圖片

輸入圖片說明

輸入圖片說明

<input type="file"  id="fileInput" value="上傳" >
            <input type="button"  id="customInput"  value="自定義樣式按鈕" onclick="TriggerOtherInputOnClickEvent()">
<script>
    function TriggerOtherInputOnClickEvent()
    {
        document.getElementById("fileInput").click();
    }
</script>
<style>
        #customInput
        {
            border-radius: 25px;
            width:140px;
            height:50px;
            border:1px;
            background-color: #FF702A;
        }
        #fileInput
        {
            display:none;
        }
    </style>
相關文章
相關標籤/搜索