Loading, please wait...

Tuesday, October 7, 2008

[转]用js获得上传图片的大小

最近想做一个关于看图的脚本,正需要这样的功能,在无忧里面发现了。
<script>
var img=null;
function s()
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=inp.value;
}
function oe()
{
alert("cant load img");
}
function orsc()
{
if(img.readyState!="complete")return false;
alert("图片大小:"+img.offsetWidth+"X"+img.offsetHeight);
alert("图片尺寸:"+img.fileSize);
}
</script>
<input id=inp type="file">
<br>
<button onclick="s()">Test</button>

转载声明: 出自: Ghoul To World!作者: GreatGhoul

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.