Getting just the filename from a path with JavaScript

前端 未结 6 568
醉话见心
醉话见心 2020-12-08 04:56

I have a full path to an image, which I am using jQuery to read like this:

$(\'img.my_image\').attr(\'src\');

However I just want the f

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 05:23

    var fileNameIndex = yourstring.lastIndexOf("/") + 1;
    var filename = yourstring.substr(fileNameIndex);
    

提交回复
热议问题