1. 可以在input上传组件上添加属性accept,这样上传文件的时候,就只能选择excel文件了。

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

2.通过正则判断

if (excel!= '') {
                var reg = /^.*\.(?:xls|xlsx)$/i;//文件名可以带空格
                if (!reg.test(path)) {//校验不通过
                    alert("请上传excel格式的文件!");
                    return;
                }
            }

 

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
猜你喜欢
  • 2021-12-29
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案