-3

CSS我只想在窗口 url 为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>
4

2 回答 2

1

您可以将这些显示规则添加到一个类中,然后根据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>
于 2020-01-31T07:58:24.247 回答
1

如果您想加载样式,请尝试使用 jquery

<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
      var pageURL = $(location).attr("href");
      console.log(pageURL);
      if( pageURL == 'https://mywebsite.com/my-account/return') {
          $('head').append('<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>');
      }
    });
  </script>
</head>
<body>
</body>
</html>
于 2020-01-31T08:05:20.603 回答