zoukankan      html  css  js  c++  java
  • js上传文件获取客户端地址

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     2 <html xmlns="http://www.w3.org/1999/xhtml"> 
     3 <head> 
     4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     5 <title>get file input full path</title>
     6 </head> 
     7 <body> 
     8 <input type="file" name="file" id="file" />
     9 <!--<img id="img" src="" alt="预览" title="预览" />-->
    10 <div class="preImg"></div>
    11 <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.2.js'></script>
    12 <script type="text/javascript">
    13 $(function() {
    14     var path,clip = $("img"),FileReader = window.FileReader;
    15 
    16     $("#file").change(function() {
    17         if (FileReader) {
    18             var reader = new FileReader(),file = this.files[0];console.log(file);
    19             reader.onload = function(e) {
    20                 //clip.attr("src", e.target.result);
    21                 var html = '<img src="'+e.target.result+'" width="300px" height="300px" />';
    22                 $('.preImg').html(html);
    23             };
    24             reader.readAsDataURL(file);
    25         } else {
    26             if(window.navigator.userAgent.indexOf("MSIE")>=1){
    27                 $(this).select();$(this).blur();
    28                 var path=document.selection.createRange().text;
    29                 /*clip.removeAttr("src");
    30                 clip.attr("src",'');
    31                 document.getElementById('img').style.filter=   
    32                 "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path+"', sizingMethod='scale');";*/
    33                 var image = new Image();
    34                 image.width = 300;
    35                 image.height = 300;
    36                 image.style.filter=   
    37                 "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path+"', sizingMethod='scale');";
    38                 $('.preImg').html(image);
    39             } else {
    40                 path = $(this).val();
    41                 if (/"wW"/.test(path)) {
    42                     path = path.slice(1,-1);
    43                 }
    44                 alert(path);
    45                 clip.attr("src",path);
    46                 alert(clip[0].src);
    47             }
    48         }
    49     });
    50 });
    51 </script> 
    52 </body> 
    53 </html>
  • 相关阅读:
    Selenium操作之滚动条
    IntelliJ IDEA代码编码区提示库源不匹配字节码解决办法
    自动化测试浅谈
    json-lib解析json之二维JSONArray
    Java 多态
    Java0基础教程——java的安装
    LAYUI弹出层详解
    ajax实现动态URL
    js serialize()
    TP5.1接入支付宝实现网页/APP支付完整请求回调流程(沙箱环境)
  • 原文地址:https://www.cnblogs.com/xingmeng/p/3399900.html
Copyright © 2011-2022 走看看