作者:挥霍无罪1988 | 来源:互联网 | 2023-10-09 19:57
我正在使用JavaScript尝试从URL获取文件名.我可以用它来得到它:varfnwindow.location.href.match(([^])+g);alert(fn[fn.
我正在使用Javascript尝试从URL获取文件名.
我可以用它来得到它:
var fn=window.location.href.match(/([^/])+/g);
alert(fn[fn.length-1]); // get the last element of the array
但有更简单的方法来获得它(例如,不必使用fn [fn.length-1]
谢谢!!
解决方法:
最后添加一个$,这样你才能得到最后一部分:
window.location.href.match(/[^/]+$/g);