You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

迁移至Neocities后style.display="block"功能失效求助

问题排查与解决方案

核心问题出在路径匹配不一致:本地Live Server允许无后缀访问页面(比如/clocktower/clocktower),但Neocities托管的页面实际访问路径会带有.html后缀(比如/clocktower/clocktower.html),导致你代码里的includes判断条件无法匹配到存储的路径。

验证方法

在places.js开头加一行alert,确认Neocities上存储的路径格式:

alert("当前页面路径:" + page + "\n已访问列表:" + JSON.stringify(list));

如果弹出的路径是带.html后缀的,就说明判断条件里的路径和实际存储的不匹配。

两种修复方案

方案1:直接修改判断条件为带.html的路径

把触发显示逻辑的判断条件改成对应页面的实际路径:

if (list.includes("/clocktower/clocktower.html") && list.includes("/stables/stables.html") && list.includes("/bank/bank.html")) {
    document.getElementById("hiddenlink").style.display="block";
    window.alert("Odd. Had I noticed that before?");
}

同时注意墓地页面的判断也要对应调整:

if (list.includes("/cemetery/cemetery.html")) {
    window.localStorage.setItem("list", "[]");
    document.getElementById("hiddenlink").style.display="none";
}

方案2:统一处理路径(推荐)

在获取page变量时,去掉.html后缀,让本地和线上的路径格式统一:

let page = String(window.location.pathname).replace(/\.html$/, '');

这样存储到localStorage的路径都会是不带.html的格式,原有的判断逻辑无需修改,同时兼容本地和线上环境。

额外检查

  • 确认hiddenlink元素在places.html中确实存在,且id拼写正确;
  • 清理浏览器缓存后重新测试,避免旧的localStorage数据干扰。

内容的提问来源于stack exchange,提问作者neuro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 05:45:13