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>
  • 相关阅读:
    EasyUI前后端分离
    easyUI权限
    EasyUI入门
    MVC(增删改查)
    MYSQL01 CentOS7下搭建mysql5.6
    Linux02:CentOS7配置静态IP
    Linux01:CentOS7桥接模式主机和虚拟机ping不通问题解决
    windows环境01 xampp+phpwind环境搭建
    Python模块之目录
    Django
  • 原文地址:https://www.cnblogs.com/xingmeng/p/3399900.html
Copyright © 2011-2022 走看看