当前位置:网站首页>js上传文件时控制文件类型和大小
js上传文件时控制文件类型和大小
2022-04-23 19:08:00 【Gis烤羊腿真好吃】
/*控制文件类型和大小 e是document*/
ConSizeType(e,[".jpg",".png",".jpeg",".JPG",".PNG",".JPEG",".pdf",".PDF",".doc"])
static ConSizeType(e,TYPE){
console.log(e.target)
var target=e.target
var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
var fileSize = 0;
var filetypes =TYPE;
var filepath = target.value;
var filemaxsize = 1024*10;//10M
if(filepath){
var isnext = false;
var fileend = filepath.substring(filepath.lastIndexOf("."));
if(filetypes && filetypes.length>0){
for(var i =0; i<filetypes.length;i++){
if(filetypes[i]==fileend){
isnext = true;
break;
}
}
}
if(!isnext){
Message({
showClose: true,
message: "不接受此文件类型",
type: 'warning'
})
target.value ="";
return false;
}
}else{
return false;
}
if (isIE && !target.files) {
var filePath = target.value;
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
if(!fileSystem.FileExists(filePath)){
Message({
showClose: true,
message: "附件不存在,请重新输入!",
type: 'warning'
})
return false;
}
var file = fileSystem.GetFile (filePath);
fileSize = file.Size;
} else {
fileSize = target.files[0].size;
}
var size = fileSize / 1024;
if(size>filemaxsize){
Message({
showClose: true,
message: "附件大小不能大于"+filemaxsize/1024+"M!",
type: 'warning'
})
target.value ="";
return false;
}
if(size<=0){
Message({
showClose: true,
message: "附件大小不能为0M!",
type: 'warning'
})
target.value ="";
return false;
}
}在这里插入代码片
版权声明
本文为[Gis烤羊腿真好吃]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_38190600/article/details/102488271
边栏推荐
- ESP32 LVGL8. 1 - textarea text area (textarea 26)
- Getting started with vcpkg
- About the operation of unit file reading (I)
- Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
- Practice of Druid SQL and security in meituan review
- SSDB foundation 3
- SSDB基础
- ESP32 LVGL8. 1 - bar progress bar (bar 21)
- Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
- MySQL restores or rolls back data through binlog
猜你喜欢
![[记录]TypeError: this.getOptions is not a function](/img/c9/0d92891b6beec3d6085bd3da516f00.png)
[记录]TypeError: this.getOptions is not a function

Druid SQL和Security在美团点评的实践

Simple use of navigation in jetpack

Using Visual Studio code to develop Arduino

Summary of actual business optimization scheme - main directory - continuous update

OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!

Esp01s with Arduino development environment

Getting started with vcpkg

On the forced conversion of C language pointer

2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)
随机推荐
Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
Seata处理分布式事务
ESP32 LVGL8. 1 - input devices (input devices 18)
: app: transformclasseswithrobustfordevrease meituan hot repair compilation error record
C1000k TCP connection upper limit test
简化路径(力扣71)
static类变量快速入门
Sentinel规则持久化进Nacos
迁移学习进阶
Esp32 (UART ecoh) - serial port echo worm learning (2)
Use of content provider
ESP32 LVGL8. 1 - img picture (IMG 20)
JVM的类加载过程
Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)
ESP32 LVGL8. 1 - roller rolling (roller 24)
The corresponding permissions required to automatically open the app in the setting interface through accessibility service
#yyds干货盘点#stringprep --- 因特网字符串预备
Esp32 (UART event) - serial port event learning (1)
Tencent map and high logo removal method
Redis optimization series (III) solve common problems after master-slave configuration