Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用javascript获取以下url - id的值?
URL: http://www.url/id/2721/John
我会得到以下值:
2721 and John
用于.split("/")将 URL 分成几部分,然后读取值。
.split("/")
使用.match(re):
.match(re)
var r = "http://www.url/id/2721/John".match('\/id\/(\\d+)/([^/]+)');
该值v[1]将是2721并且r[2]将是John。
v[1]
2721
r[2]
John