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

后端 未结 8 1625
情歌与酒
情歌与酒 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 03:49

    It is just such simple as writing:

    $('input[type=file]').val()
    

    Anyway, I suggest using name or ID attribute to select your input. And with event, it should look like this:

    $('input[type=file]').change(function(e){
      $in=$(this);
      $in.next().html($in.val());
    });
    

提交回复
热议问题