如何使用JavaScript从完整路径获取文件名?是否有一种方法可以从完整路径中获得最后一个值(基于‘\’符号)?例子:C:\Documents and Settings\img\recycled log.jpg有了这个案子,我只想recycled log.jpg从JavaScript的完整路径。
3 回答
慕运维8079593
TA贡献1876条经验 获得超5个赞
var substringTest = function (str) { return str.substring(str.lastIndexOf('/')+1);}var replaceTest = function (str) { return str.replace(/^.*(\\|\/|\:)/, '');}var execTest = function (str) { return /([^\\]+)$/.exec(str)[1];}var splitTest = function (str) { return str.split('\\').pop().split('/').pop();} substringTest took 0.09508600000000023 msreplaceTest took 0.049203000000000004 msexecTest took 0.04859899999999939 mssplitTest took 0.02505500000000005ms
翻阅古今
TA贡献1780条经验 获得超5个赞
var leafname= pathname.split('\\').pop().split('/').pop();
添加回答
举报
0/150
提交
取消