【发布时间】:2011-08-01 03:55:16
【问题描述】:
我需要解析长网址并设置一个变量(类别)等于路径中的/folders/ 之一。
例如,一个 url 是
http://example.com/community/home/whatever.html
我需要将变量设置为等于该 URL 中 /home/ 之后的任何文件夹路径。
我有这个提醒我 /community/ 之后的内容,但随后 url 变为 NaN 并且链接不起作用。我认为我没有走在正确的轨道上。
if ($(this.href*='http://example.com/community/')){
var category = url.split("community/");
alert(category[category.length - 1]);
}
想法?
TIA。
【问题讨论】:
-
抱歉,我需要将变量设置为等于该 url 中 /community/ 之后的任何文件夹路径。
-
我根本没有得到
this.href*=的东西。这是什么意思? -
jquery 选择器,如果此 href 属性包含 example.com/community
-
正如 OP 所问,他只是有做事的想法。所以我们必须给他的想法一个实现。
-
我认为
$(this.href*='http://example.com/community/')应该是$('[href*="http://example.com/community/"]')... /me shrugs
标签: javascript jquery html regex