0

我想获取没有页面的 url。请看下面。

当前网址

http://localhost/FolderPath/Page.html

想得到

http://localhost/FolderPath/

我怎样才能做到这一点?谢谢。

4

4 回答 4

1
var oldPath = 'http://localhost/FolderPath/Page.html';
var newPath = oldPath.split('/').slice(0, -1).join('/') + '/';
于 2012-09-06T03:32:17.483 回答
1
"http://localhost/FolderPath/Page.html".replace(/[^\/]*$/, '');
于 2012-09-06T03:34:36.817 回答
0

正则表达式有人吗?

var url = "http://localhost/FolderPath/Page.html";
url.match(/(.+)(\/(.+)?)$/)[1] + "/";

//returns "http://localhost/FolderPath/"

var url = "http://localhost/FolderPath/";
url.match(/(.+)(\/(.+)?)$/)[1] + "/";

//returns "http://localhost/FolderPath/"
于 2012-09-06T03:42:25.537 回答
0
var url = "http://localhost/FolderPath/Page.html";
url = url.substr(0, url.lastIndexOf('/') + 1);
于 2012-09-06T03:37:13.407 回答