How to get the fileName in javascript from input file tag in IE browser

前端 未结 3 486
终归单人心
终归单人心 2020-12-18 03:57

I have done this in jQuery, to get filename from input file tag, With jQuery it works perfectly.

3条回答
  •  萌比男神i
    2020-12-18 04:21

    I found the problem to be in getElementsByTagName method, you use this when you have a group of elements with the same tag name.

    Try this code below, it works

    //HTML
    
    
    
    // JavaScript
    document.getElementById('inp').addEventListener('change',prepareUpload,false);
    
    function prepareUpload(event)
    {
      var files = event.target.files;
      var fileName = files[0].name;
      alert(fileName);
    }
    

    Below is the code if you want to do it for more than one element

    
    
    
    
    
    
    
    
    

提交回复
热议问题