jquery怎么限制上传图片大小:
作者:
小柠有点萌 | 来源:发表于
2020-04-14 18:47 被阅读0次<input type="file" name="file" class="upload" onchange="Javascript:validate_img(this);">
//限制上传文件的类型和大小
function validate_img(ele){
// 返回 KB,保留小数点后两位
//alert((ele.files[0].size/(1024*1024)).toFixed(2));
var file = ele.value;
if(!/.(gif|jpg|jpeg|png|GIF|JPG|bmp)$/.test(file)){
alert("图片类型必须是.gif,jpeg,jpg,png,bmp中的一种");
return false;
}else{
//alert((ele.files[0].size).toFixed(2));
//返回Byte(B),保留小数点后两位
if(((ele.files[0].size).toFixed(2))>=(2*1024*1024)){
alert("请上传小于2M的图片");
return false;
}
}
alert("图片通过");
}
本文标题:jquery怎么限制上传图片大小:
本文链接:https://www.haomeiwen.com/subject/potxvhtx.html
网友评论