html input=“file“ 只显示指定文件类型 xls、xlsx、csv

这篇博客介绍了如何使用HTML的`input`元素来限制用户上传的文件类型,包括CSV、Excel(xls、xlsx)和其他常见文件格式。通过设置`accept`属性,可以确保在不同操作系统上正确过滤文件选择,例如在Mac系统中可能出现的问题及其解决方案。
摘要由CSDN通过智能技术生成
<!-- 只显示csv文件 -->
<input id="fileSelect" type="file" accept=".csv" />  

<!-- 只显示xlsx文件 -->
<input id="fileSelect" type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />  

<!-- 只显示xls文件 -->
<input id="fileSelect" type="file" accept="application/vnd.ms-excel" />  

<!-- 只显示csv、xls、xlsx文件 -->
<input id="fileSelect" type="file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />  

可能会发生的情况:

由于我自己是Mac系统,所以我的xls无法实现效果,但是在Windows和Linux是没有问题的。

可接受的类型:

  CSV 文件(.csv),请使用:

<input type="file" accept=".csv" />

  或者 

<input type="file" accept="text/csv" />

  Excel Files 2003-2007  (.xls),请使用:

<input type="file" accept="application/vnd.ms-excel" />

  Excel Files 2010  (.xlsx),请使用: 

<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />

  文本文件 (.txt),请使用: 

<input type="file" accept="text/plain" />

  图像文件 (.png / .jpg / etc),请使用: 

<input type="file" accept="image/*" />

  HTML文件 (.htm,.html),请使用:

<input type="file" accept="text/html" />

  视频文件 (.avi,.mpg,.mpeg,.mp4),请使用:

<input type="file" accept="video/*" />

  音频文件 (.mp3,.wav等),请使用:

<input type="file" accept="audio/*" />

  对于 PDF文件,请使用:

<input type="file" accept=".pdf" /> 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值