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=gb2312" />
    5 <title>get file input full path</title>
    6 <script language='javascript'>
    7 function getFullPath(obj)
    8 {
    9 if(obj)
    10 {
    11 //ie
    12 if (window.navigator.userAgent.indexOf("MSIE")>=1)
    13 {
    14 obj.select();
    15 return document.selection.createRange().text;
    16 }
    17 //firefox
    18 else if(window.navigator.userAgent.indexOf("Firefox")>=1)
    19 {
    20 if(obj.files)
    21 {
    22 return obj.files.item(0).getAsDataURL();
    23 }
    24 return obj.value;
    25 }
    26 return obj.value;
    27 }
    28 }
    29 </script>
    30 </head>
    31 <body>
    32 <input type="file" onchange="document.getElementById('img').src=getFullPath(this);" />
    33 <img id="img" />
    34 </body>
    35 </html>

    firefox7+请使用return window.URL.createObjectURL(obj.files.item(0));来获取地址

  • 相关阅读:
    如何制作静、动态库
    各种时间函数的恩与怨
    一文看懂Vim操作
    如何避免内存泄漏
    和leon一起学Vim
    shell的输入输出重定向
    和Leon一起从头学Git(六)
    和leon一起从头学Git(五)
    深入理解Linux高端内存
    和Leon一起从头学Git(四)
  • 原文地址:https://www.cnblogs.com/ahjesus/p/2354388.html
Copyright © 2011-2022 走看看