如何清除<input type="file">的值
<input type="file">選擇一個檔案,能將選中檔案的路徑填寫在類似於文字框位置,下面介紹一下如何使用js動態清除它的值,也就是路徑,可能在實際操作中用到的時候很少,不過還是寄希望能夠給需要的朋友帶來一定的幫助。
程式碼如下:
[HTML] 純文字檢視 複製程式碼<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <script type="text/javascript"> window.onload=function() { var objFile=document.getElementById('fileID'); var bt=document.getElementById('bt'); bt.onclick=function() { objFile.outerHTML=objFile.outerHTML.replace(/(value=\").+\"/i,"$1\""); } } </script> </head> <body> <input type="file" id="fileID"/> <input type="button" value="點選檢視結果" id="bt" /> </body> </html>
以上程式碼實現了我們的要求,選中檔案之後,點選按鈕可以將路徑清除。
相關閱讀:
1.onclick事件可以參閱javascript click 事件一章節。
2.replace()函式可以參閱正規表示式replace()一章節。
3.outerHTML屬性可以參閱javascript outerHTML一章節。
相關文章
- input type="file"使用
- js清空<input type="file">值程式碼例項JS
- 修改input標籤type=file型別按鈕的值型別
- type=“file”的input標籤美化
- selenium 如何清除 input 框中的 value 值?
- 如何獲取<input type="file">上傳的檔名稱
- input[type=file]使用css美化效果CSS
- 給<input type="file">增加樣式
- <input type="file"> 限制檔案型別型別
- <input type="file">美化例項程式碼
- <input type="file"> 選中多個檔案
- <input type="file">美化效果程式碼例項
- input的type值型別和描述-HTML型別HTML
- input框type=file設定cursor:pointer的問題
- 使用Input type=file 原生上傳使用總結
- jquery動態新增和刪除<input type="file" />jQuery
- input[type=file]不能選擇同一張圖片
- input[type=file] 獲取上傳檔案的內容
- jQuery動態新增或刪除<input type="file">元素jQuery
- jQuery type屬性值篩選input元素jQuery
- 動態修改input元素type屬性值
- css匹配type屬性值為text的input元素CSS
- vue3中清空input type="file"上傳檔案Vue
- JavaScript input type=file 獲取檔案大小及型別限制JavaScript型別
- HTML input type=file檔案選擇表單元素二三事HTML
- HTML5--表單標籤input新增type值HTML
- 將input type="file" 型別的圖片檔案轉成base64型別
- react input[type='number']React
- 更改input的type屬性
- utl_file.file_type使用
- css設定具有指定type屬性值的input文字框的樣式CSS
- JQuery獲取input type=jQuery
- No input file specified.
- 清空file input框
- File type 屬性
- <button>和<input type=“button“> 的區別
- <input type="button">和<button>的區別
- <input type="file">連續選中同一檔案無法觸發onchange事件事件