仅在URL为https://mywebsite.com/my-account/return时才添加CSS

问题描述 投票:-3回答:1

仅当窗口URL为CSS]时,我才想加载以下https://mywebsite.com/my-account/return

CSS:

<style>.shop table.shop_table.my_account_orders>tbody>tr{
    display: table-row !important;}

.shop table.shop_table.my_account_orders>tbody>tr>td{
    display: table-cell !important;}

.shop table.shop_table.my_account_orders>tbody>tr>td:before{
    display: table-row !important;}</style>

仅当窗口URL为https://mywebsite.com/my-account/return CSS时,我才想加载以下CSS:

您可以将这些显示规则添加到类中,然后基于window.location将其动态添加到主体中。

您的CSS规则看起来像这样(请注意新的.mywebsite-com-my-account-return类:]

<style>
    .mywebsite-com-my-account-return .shop table.shop_table.my_account_orders>tbody>tr {
        display: table-row !important;
    }

    .mywebsite-com-my-account-return .shop table.shop_table.my_account_orders>tbody>tr>td {
        display: table-cell !important;
    }

    .mywebsite-com-my-account-return .shop table.shop_table.my_account_orders>tbody>tr>td:before {
        display: table-row !important;
    }
</style>

然后您的Javascript如下所示:

<script>
    if (window.location.href === "https://mywebsite.com/my-account/return") {
        document.querySelector("body").classList.add("mywebsite-com-my-account-return")
    }
</script>
javascript jquery window.location
1个回答
0
投票

您可以将这些显示规则添加到类中,然后基于window.location将其动态添加到主体中。

© www.soinside.com 2019 - 2024. All rights reserved.