open a particular type of file using input of type="fil

open a particular type of file using input of type="file" in javascript

本文关键字:of type quot fil using particular file open input      更新时间:2023-09-26

我试图使用<input type="file" ...>打开文件并将其显示为文本。我希望弹出的对话框打开文件,以显示文件的特定扩展名,如"。txt"或"。jpg",而不是"所有文件"。我怎么能做到这一点单独使用javascript ?

您可以在输入中使用accept属性:

<input type="file" accept=".txt,.jpg">

更多信息请参见MDN