1. 替代法this
使用隱藏的<input type="file"/>控件,而後用一個只讀的文本框和一個按鈕來模擬<input type="file"/>的功能。code
<input type="file" name="file" onpropertychange="file1.value=this.value" style=display:none/>
<input type="text" name="file1" readonly/>
<input type="button" value="瀏覽" id="button1" name="button1" onclick="file.click()"/>
2. 使用腳本事件限制控件輸入blog
將<input type="file"/>控件的鼠標右鍵菜單、按鍵事件限制住,不讓用戶有機會輸入。事件
<input type="file" onkeydown="return false" onkeyup="return false" oncontextmenu="return false">
3. 使用contenteditable屬性input
使用該屬性能夠有效地限制用戶在<input type="file"/>控件中手動輸入內容,而只能經過文件選擇對話框選擇文件。it
<input type="file" id="file1" contenteditable="false" />