当前位置:网站首页>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
边栏推荐
- 7、 DOM (Part 2) - chapter after class exercises and answers
- Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)
- FTP, SSH Remote Access and control
- Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système
- Raspberry pie 18b20 temperature
- Accessing private members using templates
- Some records used by VS2010
- 为何PostgreSQL即将超越SQL Server?
- [报告] Microsoft :Application of deep learning methods in speech enhancement
- MVVM model
猜你喜欢
剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
Partage de la conception de l'alimentation électrique de commutation et illustration des compétences en conception de l'alimentation électrique
Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système
Simple use of navigation in jetpack
开关电源设计分享及电源设计技巧图解
redis优化系列(三)解决主从配置后的常见问题
mysql_ Download and installation of Linux version
Introduction to ROS learning notes (II)
解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
随机推荐
机器学习理论基础篇--关于机器学习的一些术语
Esp32 (UART event) - serial port event learning (1)
12 examples to consolidate promise Foundation
The type initializer for ‘Gdip‘ threw an exception
[advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
Simple use of viewbinding
特征选择feature_selection--SelectKBest
Sentinel service fusing practice (sentinel integration ribbon + openfeign + fallback)
Class loading process of JVM
#yyds干货盘点#stringprep --- 因特网字符串预备
SQL常用的命令
Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système
Click the input box to pop up the keyboard layout and move up
Simplified path (force buckle 71)
JVM的类加载过程
2022.04.23(LC_714_买卖股票的最佳时机含手续费)
After opening the original normal project, the dependency package displays red and does not exist.
MVVM model
ESP32 LVGL8. 1 - checkbox (checkbox 23)
Client interns of a large factory share their experience face to face