zoukankan      html  css  js  c++  java
  • JS如何获取上传标签的文件路径和文件名?

    如何使用JS获取type="file"的标签上传文件的文件路径及文件名:

    代码:

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="Generator" content="EditPlus®">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <title>Document</title>
    </head>
    <body>
    <input type="file" name="test" onchange="popFileName()" id="file">
    <script type="text/javascript">

    function getFileName(path){
    var pos1 = path.lastIndexOf('/');
    var pos2 = path.lastIndexOf('\');
    var pos = Math.max(pos1, pos2)
    if( pos<0 )
    return path;
    else
    return path.substring(pos+1);
    }

    function popFileName()
    {
    var path = document.getElementById("file").value;
    alert(path+";---;"+getFileName(path));
    }

    </script>
    </body>

  • 相关阅读:
    oracle的over函数应用(转载)
    Oracle decode()函数应用
    EL表达式显示数据取整问题
    null值与空值比较
    case when语句的应用
    堆排序
    希尔排序
    插入排序
    异或运算
    选择排序
  • 原文地址:https://www.cnblogs.com/wangqiideal/p/5056918.html
Copyright © 2011-2022 走看看