鲨鱼58

标题: 通过js添加样式代码 [打印本页]

作者: 刀哥    时间: 2024-8-12 20:30
标题: 通过js添加样式代码
  1. <script>
  2.     // 获取当前URL
  3.     var currentURL = window.location.href;

  4.     // 检查URL是否包含 "special-url"
  5.     if (currentURL.includes("special-url")) {
  6.       // 插入内联CSS
  7.       var style = document.createElement("style");
  8.       style.innerHTML = `
  9.         body {
  10.           background-color: #f0f0f0;
  11.           color: #333;
  12.         }
  13.       `;
  14.       document.head.appendChild(style);

  15.       // 输出提示信息
  16.       console.log("URL 包含 'special-url'!");
  17.     } else {
  18.       console.log("URL 不包含 'special-url'.");
  19.     }
  20.   </script>
复制代码







欢迎光临 鲨鱼58 (https://www.shayu58.com/) Powered by Discuz! X3.4