JS判断上传图片的格式是否正确
代码
function checkinfo()
{
var uploadphoto=document.getElementById("uploadPhoto");
var str = uploadphoto.value;
var tt = false;
if(uploadphoto.value=="")
{
alert('请添加上传的图片!');
return false;
}
if(str.length>0)
{
var astr = str.split(".");
var exp = astr[astr.length-1];
if(exp == "gif" || exp == "GIF" || exp == "jpg" ||exp == "JPG")
{
return true;
}
else
{
alert("上传格式不正确,上传格式应为gif或者jpg");
return false;
}
}
return true;
}

浙公网安备 33010602011771号