首页 > 解决方案 > 回到已经访问过的页面后更改一些 css 属性

问题描述

有2页,从第一页到第二页的链接。www.example.com/second.html.

然后从第二页链接到第一页的特定部分www.example.com/first.html#specificSection

有没有办法通过 Java Script 从第二页支持后更改第一页上的某些 css 属性?

标签: javascripthtmlcss

解决方案


是的。

let urlChunks = window.location.href.split('#'); 
if (urlChunks.length === 2 && urlChunks[1] === 'specificSection') {
    // add your class
}

如果length为 2,则表示在 之后找到了一个参数#,在 and 之后的条件下检查其值是否安全。


推荐阅读