在索引页面上将类添加到regex jquery

时间:2012-03-03 10:46:33

标签: jquery

提到这个问题:

add class to regex jquery

我想知道如何将此代码用于http://www.mydomain.comhttp://localhost/http://localhost:3000/或任何索引页等网页。

代码示例适用于http://localhost/username/boards

if( /^\/[^/]+\/boards/.test(location.pathname) ) {
     $("#container ul #all_categories a.categories-menu").css("font-weight","bold");
}

1 个答案:

答案 0 :(得分:0)

好的,让我们正式:

您所要做的就是测试空路径的URL:

if(location.pathname === '/')