javascript - 仅当 url 为 https://mywebsite.com/my-account/return 时添加 css
问题描述
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>
解决方案
您可以将这些显示规则添加到一个类中,然后根据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>
推荐阅读
- c# - 如何在设计师的“收藏编辑器窗口”中制作可编辑的对象?
- python - Django中的外键值分配
- c++ - C++ 运算符重载。为什么我不能正确地对其进行原型制作
- javascript - 问题面板;AddEventListener 不工作(cookies 问题)
- ios - Firebase 动态链接页面未在应用中打开 (iOS)
- javascript - html中的可编辑表格和所做的更改也将保存在电子表格中
- process - 在一个实体 vhdl 中使用两个进程时出错
- sql - 来自 SQLHelper 的 ExecuteNonQuery
- excel - 如何在 ACCESS 中导入或链接超过 255 个字段的 CSV?
- python - AttributeError:“NoneType”对象没有属性“上”