日期:2014-05-16  浏览次数:20302 次

js如何获取上传图片的大小
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <title>新建网页 1</title>
  <script>
function func()
{
var oImg=new Image();
var iFlag=false;
oImg.onload=function()
{
  if(!iFlag)
  {
   iFlag=true;
   alert("width:"+oImg.width+"\nheight:"+oImg.height+"\nfilesize:"+(oImg.fileSize/1024).toFixed(1)+"k");
  }
}
oImg.src=myform1.file1.value;
}
</script>
</head>
<body>
  <table width="50%" valign="botom" height="22" border="1">
   <!--存在两个不同表单所以需要不同的名字-->
   <form method="post" name="myform1" enctype="multipart/form-data">
   <tr>
    <td>
     <input type="file" name="file1" size="20" onchange="func()" />
    </td>
    </td>
   </tr>
   </form>
  </table>
</body>
</html>