1.带后缀名
function getFileName(path){
var pos1 = path.lastIndexOf(‘/‘);
var pos2 = path.lastIndexOf(‘\\‘);
var pos = Math.max(pos1, pos2)
if( pos<0 )
return path;
else
return path.substring(pos+1);
}
原文链接:https://blog.csdn.net/qaakd/article/details/108058545
2.不带后缀名
getFileName(path) {
var pos1 = path.lastIndexOf(‘/‘)
var pos2 = path.lastIndexOf(‘\\‘)
var pos = Math.max(pos1, pos2)
if (pos < 0) {
return path
}
else {
let tempPath = path.substring(pos + 1);
return tempPath.substring(0, tempPath.lastIndexOf("."));
}
}