当前位置:网站首页>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
边栏推荐
- Class loading process of JVM
- OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
- [play with lighthouse] Tencent cloud lightweight server builds a full platform video analysis video download website
- ESP32 LVGL8. 1 - slider slider (slider 22)
- [today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
- One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
- 高层次人才一站式服务平台开发 人才综合服务平台系统
- One stop service platform for high-level talents and development of comprehensive service platform system for talents
- 2022.04.23(LC_763_划分字母区间)
- Wechat video extraction and receiving file path
猜你喜欢
12个例子夯实promise基础
解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
[记录]TypeError: this.getOptions is not a function
ESP32 LVGL8. 1 - checkbox (checkbox 23)
为何PostgreSQL即将超越SQL Server?
2022.04.23(LC_714_买卖股票的最佳时机含手续费)
8266 obtain 18b20 temperature
ESP32 LVGL8. 1 - slider slider (slider 22)
[record] typeerror: this getOptions is not a function
Client interns of a large factory share their experience face to face
随机推荐
Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)
微搭低代码零基础入门课(第三课)
简化路径(力扣71)
The type initializer for ‘Gdip‘ threw an exception
Fundamentals of machine learning theory -- some terms about machine learning
ESP32 LVGL8. 1 - textarea text area (textarea 26)
Usage of functions decode() and replace() in SQL
Disable Ctrl + Alt + Del
Screen right-click menu in souI
FTP、ssh远程访问及控制
After opening the original normal project, the dependency package displays red and does not exist.
PyGame tank battle
SSDB foundation 1
该买什么设备,Keysight 给你挑好了
ESP32 LVGL8. 1 - slider slider (slider 22)
Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
The corresponding permissions required to automatically open the app in the setting interface through accessibility service
Treatment of incomplete display of listview height
Sentinel规则持久化进Nacos
Go language GUI framework Fyne Chinese garbled or not displayed