Get the file name after click open button in file browse dialog box using JavaScript/jQuery

前端 未结 4 1512
忘了有多久
忘了有多久 2021-01-20 02:53

Basically I am new in web development and I\'m facing a problem related to open file dialog box using JavaScript or jQuery my problem

相关标签:
4条回答
  • 2021-01-20 03:28

    I think this is right...Should produce a "Browse" button:

    <input id="file_field" type="file"></input>
    
    <button type="button" onclick="DisplayFilePath();">Display file path</button>
    
    <script>
    function DisplayFilePath(){
        alert($("#file_field").val())
    }
    </script>
    
    0 讨论(0)
  • 2021-01-20 03:33

    Just get the value of the <input type="file" />.

    0 讨论(0)
  • 2021-01-20 03:39

    try this:

    <SCRIPT>
        function reverseData(val)       {var d="";var temp="";for (var x=val.length;x>0;x--) {d+=val.substring(x,eval(x-1));}return d;}
        function getFilename(val)       {val=escape(val);var reversedsrc=reverseData(val);var nameEnd=reversedsrc.indexOf('C5%');var name=reversedsrc.substring(0,nameEnd);name=reverseData(name);name=unescape(name);return name;}
        var daname='val';
        document.write('<INPUT TYPE="file" ID="val"><INPUT TYPE="button" VALUE="Get File Name" ONCLICK="alert(getFilename(window.document.getElementById(daname).value))">');
    </SCRIPT>
    

    put it into html file and test

    0 讨论(0)
  • 2021-01-20 03:40
    <form>
        <input type="file">
    </form>
    <script>
      $(":file").change(function(){
        alert($(":file").val());
      });
    </script>
    

    put it on jsfiddle for you here: http://jsfiddle.net/9ytkn/

    0 讨论(0)
提交回复
热议问题