1.

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5     <head>
 6     </head>
 7     <script type="text/javascript">
 8         var flag=false;
 9         function DrawImage(ImgD) {
10             var image=new Image();
11             image.src=ImgD.src;
12             if(image.width>0 && image.height>0) {
13                 flag=true;
14                 if(image.width/image.height>= 120/80) {
15                     if(image.width>120) {
16                         ImgD.width=120;
17                         ImgD.height=(image.height*120)/image.width;
18                     } else {
19                         ImgD.width=image.width;
20                         ImgD.height=image.height;
21                     }
22                     ImgD.alt=image.width+"×"+image.height;
23                 } else {
24                     if(image.height>80) {
25                         ImgD.height=80;
26                         ImgD.width=(image.width*80)/image.height;
27                     } else {
28                         ImgD.width=image.width;
29                         ImgD.height=image.height;
30                     }
31                     ImgD.alt=image.width+"×"+image.height;
32                 }
33             }
34             /*else{
35              ImgD.src="";
36              ImgD.alt=""
37              }*/
38         }
39 
40         function FileChange(Value) {
41             flag=false;
42             document.all.uploadimage.width=10;
43             document.all.uploadimage.height=10;
44             document.all.uploadimage.alt="";
45             document.all.uploadimage.src=Value;
46         }
47 
48         function FileChange1(Value) {
49             flag=false;
50             document.all.uploadimage1.width=10;
51             document.all.uploadimage1.height=10;
52             document.all.uploadimage1.alt="";
53             document.all.uploadimage1.src=Value;
54         }
55 
56         function BeforeUpLoad() {
57             if(flag)
58                 alert("OK");
59             else
60                 alert("FAIL");
61         }
62     </script>
63     <body>
64         <IMG id="uploadimage" height=10 width=10 src=""
65         onload="javascript:DrawImage(this);"   >
66         <input type="file"  id="upload" onchange="javascript:FileChange(this.value);"/>
67     </body>
68 </html>

 

posted on 2017-01-18 22:49  Sharpest  阅读(217)  评论(0编辑  收藏  举报