Get only file name from file input on internet explorer

前端 未结 3 2093
孤独总比滥情好
孤独总比滥情好 2021-02-09 06:33

I need to return only the file name from an HTML input file.


The JavaScript code im using to get

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-09 07:16

    var path = document.getElementById("whatever").value;
    var filename = path.substring(path.lastIndexOf("/") + 1);
    

    This will give you everything after the last /, but is also compatible with a lack of /s. In case you also need to deal with \ as the lovely path separator, you can always use this first:

    path.replace(/\\/g, "/")
    

提交回复
热议问题