javascript判斷上傳圖片的大小和格式

來源:互聯網
上載者:User
  1. 以下為引用的內容:
  2. <!DOCTYPE    HTML    PUBLIC    "-//W3C//DTD    HTML    4.0    Transitional//EN">   
  3.    <HTML>   
  4.    <HEAD>   
  5.    <TITLE>    New    Document    </TITLE>   
  6.    <META    NAME="Author"    CONTENT="寶玉">   
  7.    </HEAD>   
  8.    <script    language="javascript">    
  9. php程式員站
  10.            <!--   
  11.    //檢查插入是否為圖片   
  12.    var    img=null;   
  13.    function    chkimg(inp)   
  14.    {   
  15.    if(img)img.removeNode(true);   
  16.    img=document.createElement("img");   
  17.    img.attachEvent("onreadystatechange",isimg);   
  18.    img.attachEvent("onerror",notimg);   
  19.    img.src=inp;   
  20.    }   
  21.    function    notimg()   
  22.    {   
  23.    alert("您插入的不是圖片,請重新選擇插入");   
  24.    }   
  25.    function    isimg()    phperz~com 
  26.    {   
  27.    show.insertAdjacentElement("BeforeEnd",img);   
  28.    show1.innerHTML  =  "圖片大小"+ img.fileSize/1024+"K<br/>圖片寬度"+img.offsetWidth+"<br/>圖片高度"+img.offsetHeight;   
  29.    }   
  30.     
  31.    //    -->   
  32.    </script>   
  33.    <BODY>   
  34.    <div    id="show"></div>   
  35.    <div    id="show1"></div>   
  36.    <input    type="file"    name=""    onpropertychange="chkimg(this.value)"/>   
  37.    </BODY>   
  38.    </HTML> 
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.