【www.gdgbn.com--js教程】



   
       
       
       
   
   
        <script>
            function getImageSize(obj){
                var url,image;
                if(obj.files){
                    url=obj.files[0].getAsDataURL();
                }else{
                    url=obj.value;
                    url=url.replace(/\/g,"/");
                    url="file:///"+url;
                }
                image=new Image();
                image.src=url;
                image.onload=function(){
                    alert(image.width+":"+image.height)   
                }
            }
        </script>
       
   

方法二



<script>
function ShowImg(o){
 document.getElementById("idImg").src = o.files[0].getAsDataURL();
 document.getElementById("idImg").style.display = "block";
}
</script>

方法三。

<script>
var img=null;
var xianzhiheight=60;//限制尺寸的高度
var xianzhiwidth=80;//限制尺寸的宽度
function yanzheng()
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
document.body.insertAdjacentElement("beforeend",img);
img.src=form1.file.value;
if (img.offsetHeight>xianzhiheight)
{
alert("您选择的图片超过了上传限制的最大高度:"+xianzhiheight);
document.form1.file.outerHTML=document.form1.file.outerHTML.replace(/value=w/g,"");
return false;
}
if (img.offsetWidth>xianzhiwidth){
alert("您选择的图片超过了上传限制的最大宽度:"+xianzhiwidth);
document.form1.file.outerHTML=document.form1.file.outerHTML.replace(/value=w/g,"");
return false;
}
}
</script>




本文来源:http://www.gdgbn.com/wangyezhizuo/20313/