From a65ec682cea28581a279a25940a0d719a3b410a3 Mon Sep 17 00:00:00 2001 From: nxxy335 Date: Thu, 10 Sep 2026 12:50:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=8A=A5=20Cannot=20set=20properties=20of=20?= =?UTF-8?q?null=20(setting=20'textContent')?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:#fullScoresHint 是 #fullScoresBox 的子元素,而 renderFullScores() 用 box.innerHTML 渲染试卷列表时会把它销毁,紧接着的 $('#fullScoresHint').textContent = ... 即变成 null.textContent 抛错。 只要 state.projects 非空(连上卷王、有可答卷)点设置必触发; projects 为空时走 early return 反而不报错,故此前长期潜伏未被发现 (自 8686eb9 设置重构引入)。 修复: - index.php:把 #fullScoresHint 移出 #fullScoresBox,改为兄弟元素, 并加注释说明为何不能放回去 - assets/app.js:新增 setFullScoresHint() 带 null 守卫,三个分支统一走它; 即使将来 DOM 结构再变动也不会让整个设置弹窗打不开 --- assets/app.js | 11 ++++++++++- index.php | 6 ++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/assets/app.js b/assets/app.js index d6074e9..b9022a6 100644 --- a/assets/app.js +++ b/assets/app.js @@ -833,17 +833,26 @@ } // 渲染"各试卷独立满分"列表 + // 注意:#fullScoresHint 必须位于 #fullScoresBox 之外(见 index.php), + // 否则 box.innerHTML 覆盖会销毁它,下面的 textContent 赋值会抛 "Cannot set properties of null"。 + // 这里仍保留 null 守卫,避免任何 DOM 结构变动导致整个设置弹窗打不开。 + function setFullScoresHint(text) { + const hint = $('#fullScoresHint'); + if (hint) hint.textContent = text; + } function renderFullScores(scores) { const box = $('#fullScoresBox'); if (!box) return; if (!state.projects.length) { box.innerHTML = '暂无试卷,请先连接卷王系统并选择问卷'; + setFullScoresHint('给某卷填入数字即可单独覆盖默认满分;留空=用默认'); return; } // 排除文件夹项:模式为文件夹的无可答卷 const surveys = state.projects.filter(p => !((p.mode || '').toLowerCase().includes('folder'))); if (!surveys.length) { box.innerHTML = '尚未获取到可答卷'; + setFullScoresHint('给某卷填入数字即可单独覆盖默认满分;留空=用默认'); return; } box.innerHTML = surveys.map(p => { @@ -853,7 +862,7 @@ '' + ''; }).join(''); - $('#fullScoresHint').textContent = '默认分值为空时使用上方"默认满分";填写即单独覆盖该卷'; + setFullScoresHint('默认分值为空时使用上方"默认满分";填写即单独覆盖该卷'); } /* ---------------- 名单 ---------------- */ diff --git a/index.php b/index.php index 4c73aab..46c4b73 100644 --- a/index.php +++ b/index.php @@ -211,9 +211,11 @@ $rosterCount = Roster::count();
- 未选中试卷时,此处为空;选中某套试卷后保存即在设置中为该卷单独设定满分 + 未选中试卷时,此处为空;选中某套试卷后保存即在设置中为该卷单独设定满分
-

给某卷填入数字即可单独覆盖默认满分;留空=用默认

+ +

给某卷填入数字即可单独覆盖默认满分;留空=用默认