This question already has answers here:
Limit file format when using <input type=“file”>?
                                
                                    (9个答案)
                                
                        
                                2年前关闭。
            
                    
如何使accept属性接受css文件类型或js文件?

<input type="file" name="NAME" id="fileinput2" accept=".css" onchange="check()" />


谢谢

最佳答案

像这样:

<input type="file" name="NAME" id="fileinput2" accept=".css,.js" />


但是W3C建议在accept属性中同时指定MIME类型和相应的扩展名。因此,最好的方法是:

<input type="file" name="NAME" id="fileinput2" accept=".css, .js, text/css, application/x-javascript" />


有关完整的Mime类型,请参考this

10-06 04:21