Javascript 在url中查找字符串位置并替换url
假设我现在在:Javascript 在url中查找字符串位置并替换url,javascript,html,Javascript,Html,假设我现在在: http://example.com/page/1/foo/something/here 因此,我需要做的是搜索window.location.href中的特定字符串,在本例中为foo,我需要在字符串foo之前搜索url,因此在本例中为 http://example.com/page/1/ 我怎样才能做到这一点呢?有很多方法。以下是最短的: 'http://example.com/page/1/foo/something/here'.split('foo')[0] 有很多方
http://example.com/page/1/foo/something/here
因此,我需要做的是搜索window.location.href中的特定字符串,在本例中为foo,我需要在字符串foo之前搜索url,因此在本例中为
http://example.com/page/1/
我怎样才能做到这一点呢?有很多方法。以下是最短的:
'http://example.com/page/1/foo/something/here'.split('foo')[0]
有很多方法。以下是最短的:
'http://example.com/page/1/foo/something/here'.split('foo')[0]