獲取 input[type=file] 檔案上傳尺寸
阿新 • • 發佈:2018-12-02
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <form id="form1" runat="server"> <div> <input type="file" name="f" id="f" /> <input type="button" name="aa" id="aa" value="測試" onclick="javascript: _s();" /> </div> </form> </body> </html> <script type="text/javascript"> function _s() { var f = document.getElementById("f").files; //上次修改時間 alert(f[0].lastModifiedDate); //名稱 alert(f[0].name); //大小 位元組 alert(f[0].size); //型別 alert(f[0].type); } </script> 判斷檔案型別 var type=(src.substr(src.lastIndexOf("."))).toLowerCase(); if(type!=".jpg"&&type!=".gif"&&type!=".jpeg"&& type!=".png"){ alert("您上傳圖片的型別不符合(.jpg|.jpeg|.gif|.png)!"); return false; }