From 4eb134bea9abef815ecfb83d900c60f79a4806bf Mon Sep 17 00:00:00 2001 From: yiqiu Date: Wed, 17 Dec 2025 16:41:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B3=A8=E5=86=8C=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98=20-=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=AE=A1=E7=AE=97=E5=90=8E=E7=9A=84=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E7=99=BB=E5=BD=95=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:JavaScript 检查的是 inline style.display 而不是计算后的样式 - HTML 中 no-login 元素有 style="display: none" - JavaScript 看到 style.display === 'none' 判断已登录 - 实际上 CSS 已经设置 display: flex !important 解决方案: - 使用 window.getComputedStyle() 获取实际应用的样式 - 添加 else 分支确保默认显示未登录状态 - 显式设置 inline style.display = 'flex' 来覆盖 HTML 中的 display: none 现在注册按钮应该正常显示! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- js/tools.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/js/tools.js b/js/tools.js index beb61e5..39132ca 100644 --- a/js/tools.js +++ b/js/tools.js @@ -52,13 +52,21 @@ $(function () { const mobileNoLogin = document.querySelector('.mobile-no-login'); const mobileLoginIn = document.querySelector('.mobile-login-in'); + // 使用计算后的样式而不是 inline style + const noLoginComputedDisplay = desktopNoLogin ? window.getComputedStyle(desktopNoLogin).display : 'none'; + const loginInComputedDisplay = desktopLoginIn ? window.getComputedStyle(desktopLoginIn).display : 'none'; + // 检查桌面端登录状态 - if (desktopNoLogin && desktopNoLogin.style.display !== 'none') { + if (desktopNoLogin && noLoginComputedDisplay !== 'none') { // 未登录 + desktopNoLogin.style.display = 'flex'; + if (desktopLoginIn) desktopLoginIn.style.display = 'none'; if (mobileNoLogin) mobileNoLogin.style.display = 'block'; if (mobileLoginIn) mobileLoginIn.style.display = 'none'; - } else if (desktopLoginIn && desktopLoginIn.style.display !== 'none') { + } else if (desktopLoginIn && loginInComputedDisplay !== 'none') { // 已登录 + if (desktopNoLogin) desktopNoLogin.style.display = 'none'; + desktopLoginIn.style.display = 'flex'; if (mobileNoLogin) mobileNoLogin.style.display = 'none'; if (mobileLoginIn) mobileLoginIn.style.display = 'block'; @@ -74,6 +82,12 @@ $(function () { if (desktopHeadImg && mobileHeadImg) { mobileHeadImg.textContent = desktopHeadImg.textContent; } + } else { + // 默认显示未登录状态 + if (desktopNoLogin) desktopNoLogin.style.display = 'flex'; + if (desktopLoginIn) desktopLoginIn.style.display = 'none'; + if (mobileNoLogin) mobileNoLogin.style.display = 'block'; + if (mobileLoginIn) mobileLoginIn.style.display = 'none'; } }