一、html页面
<input type="file" name="file" id="uploadFileId" style="display:none;" data-suffix=".rar,.zip"/>
二、jQuery
function checkFile(uploadFileId, maxSize) {
var flag = true;
var file = $("#" + uploadFileId);
var suffix = file.data("suffix");
if (suffix) {
var arr = suffix.split(',');
var fileName = file.val();
var fileSuffix = fileName.substr(fileName.lastIndexOf('.'));
if ($.inArray(fileSuffix, arr) < 0){
alert('文件格式不正确');
flag = false;
}
}
if (maxSize != undefined) {
if(file.get(0).files[0].size > 1024 * 1024 * maxSize) {
alert('文件不能大于' + maxSize + 'M');
flag = false;
}
}
return flag;
}