Use jQuery to get the file input's selected filename without the path

后端 未结 14 838
醉话见心
醉话见心 2020-11-27 10:02

I used this:

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

to get the file name selected, but it returned the full path, as in \"C:\\fakepath\\filename.doc

14条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 10:38

    How about something like this?

    var pathArray = $('input[type=file]').val().split('\\');
    alert(pathArray[pathArray.length - 1]);
    

提交回复
热议问题