From fc585abcdf79fe8d51efd6af24228a5ddcec4d35 Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 14 Jun 2024 18:55:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96value=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E7=BB=91=E5=AE=9A,=20=E8=87=AA=E5=8A=A8=E8=BD=AC=E4=B8=BA?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/html.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/html.js b/src/html.js index a729c2a..70c8f53 100644 --- a/src/html.js +++ b/src/html.js @@ -13,11 +13,13 @@ const MARKER = `{{^wkit${String(Math.random()).slice(-8)}^}}` const MARKER_MATCH = '?' + MARKER const NODE_MARKER = `<${MARKER_MATCH}>` +// 是否原始值 const isPrimitive = value => - value === null || (typeof value != 'object' && typeof value != 'function') + value === null || (typeof value !== 'object' && typeof value !== 'function') const isArray = Array.isArray const isIterable = value => value ? isArray(value) || typeof value[Symbol.iterator] === 'function' : false + const SPACE_CHAR = `[ \n\f\r]` const ATTR_VALUE_CHAR = `[^ \n\f\r"'\`<>=]` const NAME_CHAR = `[^\\s"'>=/]` @@ -573,10 +575,15 @@ class AttributePart { elem.removeAttribute(attr) } } else { - if (value === null || value === void 0) { - elem.removeAttribute(attr) + // value 绑定, 特殊处理 + if (attr === 'value') { + elem.value = value } else { - elem.setAttribute(attr, value) + if (value === null || value === void 0) { + elem.removeAttribute(attr) + } else { + elem.setAttribute(attr, value) + } } } }