1function CheckFile(f,p)
2{
3//判斷圖片尺寸
4var img=null;
5img=document.createElement("img");
6document.body.insertAdjacentElement("beforeend",img);
7img.style.visibility="hidden";
8img.src=f;
9var imgwidth=img.offsetWidth;
10var imgheight=img.offsetHeight;
11if(p.name=="UpFile_Photo1")
12{
13if(imgwidth!=68||imgheight!=68)
14{
15alert("小圖的尺寸應該是68x68");
16}
17}
18if(p.name=="UpFile_Photo2")
19{
20if(imgwidth!=257||imgheight!=351)
21{
22alert("中圖的尺寸應該是257x351");
23}
24}
25if(p.name=="UpFile_Photo3")
26{
27if(imgwidth!=800||imgheight!=800)
28{
29alert("大圖的尺寸應該是800x800");
30}
31}
32//判斷圖片類型
33if(!/\.(gif|jpg|jpeg|bmp)$/.test(f))
34{
35alert("圖片類型必須是.gif,jpeg,jpg,bmp中的一種")
36return false;
37}
38return true;
39}
1<input type="file" id="UpFile_Photo1" runat="server" name="UpFile_Photo1"
2size="35" onpropertychange="CheckFile(this.value,this)">小圖<br />
3<input type="file" id="UpFile_Photo2" runat="server" name="UpFile_Photo2"
4size="35" onpropertychange="CheckFile(this.value,this)">中圖<br />
5<input type="file" id="UpFile_Photo3" runat="server" name="UpFile_Photo3"
6size="35" onpropertychange="CheckFile(this.value,this)">大圖<br />
轉自 http://www.cnblogs.com/lixx/archive/2008/06/12/1218599.html