温馨提示:本文翻译自stackoverflow.com,查看原文请点击:javascript - Add css only when url is https://mywebsite.com/my-account/return

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

发布于 2020-03-27 15:40:33

我只想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>

查看更多

查看更多

提问者
Akash Malviya
被浏览
24
semplon 2020-01-31 16:05

如果要加载样式,请尝试使用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>