easyui版本 1.5.5.4
$.extend($.fn.filebox.defaults,{
onChange:function(newV,oldV){
if(newV=='')return;
var expArr = ['.jpg','.gif','.png','.jpeg','.doc','.docx','.xls','.csv','.xlsx','.ppt','.zip','.rar','.7z','.txt'];
var isValidate = false;
for(x in expArr){
if(newV.slice(-expArr[x].length)==expArr[x]){
isValidate = true;
break;
}
}
if(!isValidate){
util.clearFileBoxByJObj($(this));
alert('选择文件类型错误');
}
}
});
util.clearFileBoxByJObj = function(jqueryObj){
jqueryObj.next().children('input:first').val('');
jqueryObj.next().children('input:last').val('');
}
本文介绍如何使用EasyUI 1.5.5.4版本进行文件上传类型验证。通过JavaScript扩展默认行为,确保只允许特定格式的文件被上传,如图片、文档等,并在不合规时清除文件并提示用户。
1326

被折叠的 条评论
为什么被折叠?



