jQuery: get the file name selected from <input type=“file” />

后端 未结 8 1264
情歌与酒
情歌与酒 2020-11-27 03:35

This code should work in IE (don\'t even test it in Firefox), but it doesn\'t. What I want is to display the name of the attached file. Any help?

         


        
相关标签:
8条回答
  • 2020-11-27 04:01
    //get file input
    var $el = $('input[type=file]');
    //set the next siblings (the span) text to the input value 
    $el.next().text( $el.val() );
    
    0 讨论(0)
  • 2020-11-27 04:02
    $('input[type=file]').change(function(e){
        $(this).parents('.parent-selector').find('.element-to-paste-filename').text(e.target.files[0].name);
    });
    

    This code will not show C:\fakepath\ before file name in Google Chrome in case of using .val().

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