如果url有/ shop /添加类

时间:2016-08-28 20:09:40

标签: jquery squarespace

我正在SquareSpace商店工作,不幸的是,对于我来说,所有商店页面都没有添加任何课程。我的意思是任何以http://example.com/shop/

开头的页面

我想为所有以此网址开头的网页添加一个类,无论是http://example.com/shop/item1http://example.com/shop/category/category-name等。

我试过了,但没有课程被添加到<body>

$(document).ready(function() {
    if(url.indexOf('/shop/') > -1){
        $("body").addClass("shop");
    }
});

我该如何做到这一点?

3 个答案:

答案 0 :(得分:2)

您可以使用window.location.pathname中的shop/index.html

$(document).ready(function() {
    if(window.location.pathname.match('shop')){
        $("body").addClass("shop");
    }
});

答案 1 :(得分:1)

public async ....
await db.SaveChangeAsync();

答案 2 :(得分:1)

你可以使用普通的Javascript,例如

TextInputLayout

使用if (document.location.pathname.indexOf("/shop/") == 0) { document.body.className = "shop"; } ,对于以indexOf开头的所有路径名,它将返回true。如果是这样,它会将类/shop/添加到shop元素。

因此,对于以<body>开头的每个网址,shop都会获得body ID