修复注册按钮显示问题 - 使用计算后的样式检查登录状态
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
问题: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 <noreply@anthropic.com>
This commit is contained in:
18
js/tools.js
18
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';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user