预览图片代码

 1 <!DOCTYPE html> 
 2 <html>  
 3 <head>  
 4 <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>  
 5 <script type="text/javascript">  
 6     $(function(){  
 7         function getObjectURL(file){    
 8             var url=null     
 9             if(window.createObjectURL!=undefined){ // basic    
10                 url=window.createObjectURL(file)    
11             }else if(window.URL!=undefined){ // mozilla(firefox)    
12                 url=window.URL.createObjectURL(file)    
13             } else if(window.webkitURL!=undefined){ // webkit or chrome    
14                 url=window.webkitURL.createObjectURL(file)    
15             }    
16             return url;  
17         }    
18         $("#face_upload").change(function(){ 
19             var objUrl=getObjectURL(this.files[0]); 
20             var size=this.files[0].size;    
21             if(size>=1024000*10)bottomTip("图片超过10M了哦",0);    
22             else{    
23                  if(objUrl){    
24                         $("#xs").attr("src",objUrl);  
25                     }    
26             }     
27         })  ;  
28     })  
29 </script>  
30 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
31 <title>Insert title here</title>  
32 </head>  
33 <body>  
34     <form  enctype="multipart/form-data">  
35         商品图片 <input type="file" id="face_upload"/><br>  
36         <img src="" height="200" width="200" id="xs"/>  
37     </form>  
38 </body>  
39 </html>

 效果如下:

 

转载于:https://www.cnblogs.com/liuna/p/7141995.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值