我正在SquareSpace商店工作,不幸的是,对于我来说,所有商店页面都没有添加任何课程。我的意思是任何以http://example.com/shop/
我想为所有以此网址开头的网页添加一个类,无论是http://example.com/shop/item1
,http://example.com/shop/category/category-name
等。
我试过了,但没有课程被添加到<body>
。
$(document).ready(function() {
if(url.indexOf('/shop/') > -1){
$("body").addClass("shop");
}
});
我该如何做到这一点?
答案 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 。