用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.offsetHeight+":"+img.offsetWidth);
}
</script>
<input id=inp style="width:400" value="images/logo.gif">
<br>
<button onclick="s()">show</button>

 

你可能感兴趣的:(js)