:js实现上传图片时 点击浏览后 就可以看到缩略图 很实用

转载网址:http://blog.sina.com.cn/s/blog_6094f04d0100o6kj.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head>

<SCRIPT   LANGUAGE="JavaScript">     

var   flag=false;   

function   DrawImage(ImgD){ 

    var image=new   Image();

    image.src=ImgD.src;

    if(image.width>0   &&   image.height>0){ 

    flag=true;      

    if(image.width>300 || image.height>200)     {

      ImgD.width=image.width/2; 

                 ImgD.height=image.height/2;

      ImgD.alt=image.width+"×"+image.height;

    }    else    {

      ImgD.width=image.width;  

      ImgD.height=image.height; 

              ImgD.alt=image.width+"×"+image.height; 

    }  

  }   

}  

 

function   mainChange(Value){ 

  flag=false;

  document.all.mainimage.width=5; 

  document.all.mainimage.height=5;

  document.all.mainimage.alt=""; 

  document.all.mainimage.src=Value; 

   document.all.maindiv.style.display=''; 

}

</SCRIPT>

<TABLE   border="0">

  <TBODY>

    <tr> 

      <td   height="22"   colspan="5">        

        top:<input   type="file"   name="up1"   style="width:300"   class="textbox"  onChange="javascript:mainChange(this.value);"> 

      </td>                

    </tr>        

  </TBODY>    

</TABLE>        

<table height="78"   border="0"   cellpadding="0"   cellspacing="0">       

  <tr>                

    <td  >

      <div   id="maindiv" style="display:none">      

        <IMG   id=mainimage height=70 width=20 src="" onload="javascript:DrawImage(this);"   >      

      </div>

    </td>               

  </tr>        

</table>

<body> </body>

</html>

你可能感兴趣的:(缩略图)