From 3284269399216bf19af8bf44b4275776ed765e57 Mon Sep 17 00:00:00 2001 From: zikai Date: Tue, 21 Jul 2026 14:41:10 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=8D=E9=80=89=E6=A1=86=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E7=8A=B6=E6=80=81=E9=94=99=E8=AF=AF=EF=BC=88el=20?= =?UTF-8?q?=E5=AF=B9=E5=B8=83=E5=B0=94=E5=B1=9E=E6=80=A7=E7=94=A8=20setAtt?= =?UTF-8?q?ribute=20=E5=AF=BC=E8=87=B4=20checked:false=20=E4=BB=8D?= =?UTF-8?q?=E5=8B=BE=E9=80=89=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit common.js 的 el() 对 checked/disabled/hidden 等布尔属性调用 setAttribute(k, v), 而 setAttribute("checked", "false") 仍会令 checkbox 呈勾选态(属性存在即为真)。 改为维护 BOOL_PROPS 集合,布尔属性用 node[k] = !!v 赋值;同时 v === false 时跳过 setAttribute。 修复后文件浏览页复选框初始未选中时正确显示为未勾选。 --- static/common.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/static/common.js b/static/common.js index 7c98781..64c272c 100644 --- a/static/common.js +++ b/static/common.js @@ -3,6 +3,12 @@ (function (global) { "use strict"; + // 布尔属性:用属性赋值而非 setAttribute(setAttribute("checked","false") 仍会勾选) + const BOOL_PROPS = new Set([ + "checked", "disabled", "readonly", "selected", "hidden", "multiple", "open", + "autofocus", "required", "async", "defer", "controls", "autoplay", "loop", "muted", + ]); + function el(tag, attrs, ...children) { const node = document.createElement(tag); if (attrs) { @@ -11,7 +17,8 @@ else if (k === "dataset") Object.assign(node.dataset, v); else if (k.startsWith("on") && typeof v === "function") node.addEventListener(k.slice(2).toLowerCase(), v); - else if (v !== null && v !== undefined) node.setAttribute(k, v); + else if (BOOL_PROPS.has(k)) node[k] = !!v; + else if (v !== null && v !== undefined && v !== false) node.setAttribute(k, v); } } for (const c of children) {