使用jQuery或PHP将“.active”类添加到菜单中的当前页面链接

我需要在页面上的活动任务菜单链接上添加.active类。 我正在使用localhost,这里有几个示例url:

 http://localhost/webapp/https://stackoverflow.com/questions/13349046/add-active-class-to-the-current-pages-link-in-a-menu-using-jquery-or-php/index.php?task=validate http://localhost/webapp/https://stackoverflow.com/questions/13349046/add-active-class-to-the-current-pages-link-in-a-menu-using-jquery-or-php/index.phphttps://stackoverflow.com/?task=register 

和菜单的结构:

   

您可以使用jQuery循环遍历所有链接并将其URL与location进行比较。 这是一个例子:

 $(".sf-menu a").filter(function(){ return this.href == location.href.replace(/#.*/, ""); }).addClass("active");