代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>图片等比例缩小js代码_www.jb200.com</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script language="javascript"> 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); btn.disabled=false; } </script> </head> <body> <input id=inp type="file" onChange="s();"> <br> <button onclick="s()">Test</button><button id=btn disabled>UpLoad</button> </body> </HTML>
代码比较简洁,实现了基本的剪切功能,还是很不错的,有兴趣的朋友,亲自动手测试下吧。