您的位置:首页 > Web前端 > JavaScript

js实现上传图片类型大小的检测代码

2011-04-06 11:24 806 查看
js实现上传图片类型大小的检测代码

var img=null;

function showtype()

{

if(document.up.title.value=="")

{alert("请输入照片说明!");

document.up.title.focus();

return false;

}

var fsize=0;

if(img)img.removenode(true);

img=document.createelement("img");

img.style.position="absolute";

img.style.visibility="hidden";

document.body.insertadjacentelement("beforeend",img);

img.src=up.inp.value;

var ftype=img.src.substring(img.src.length-4,img.src.length)

ftype=ftype.touppercase();

fsize=img.filesize;

if((ftype.indexof('jpg',0)==-1) && (ftype.indexof('gif', 0)==-1))

{ alert("sorry!上传失败!nn请选择您要上传的照片nn且只能是.jpg或.gif图片类型。");

return false;

}

alert("您确定要上传此文件吗?");

//return confirm("文件尺寸:宽"+img.offsetwidth+"px x 高"+img.offsetheight+"px");

if(img.filesize<0)

{alert("文件类型错误!只能是.jpg或.gif图片类型www.3ppt.com。");

return false;

}

if(img.filesize>512000)

{alert("文件大小超出500k,请重新选择!");

return false;

}

return true;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息