开发者

Jquery/Js - Strip out text from URL

Here is my url:

https://sub.domain.com/core/subsite/piano/page/...

I need to take the string 'piano', and then apply it to elements on the page. The string will not always be 'piano', i need to take the 3rd section of the URL.

(Below is what I currently have which uses the breadcrumb of the page to identify what page the users is currently viewing) however I'd like t开发者_如何学Co take 'piano' as the class to apply:

$(function() {
    $('span .breadcrumb').each(function(){
        $('#Nav').addClass($(this).text());
        $('#Content').addClass($(this).text());
        $('.xpanding_footer').addClass($(this).text())
        $('#footer').addClass($(this).text());
    });
});


I can only guess that you are asking about third parameter in pathname when you are splitting using backslash.

So, you can get the value using:

window.location.pathname.split('/')[3]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜