From ec64da1f37a1481f049ee946360e9059249bfe7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Sat, 7 Oct 2023 00:49:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20createElement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/weigets.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/public/weigets.js b/public/weigets.js index 9fa7c96..248df80 100644 --- a/public/weigets.js +++ b/public/weigets.js @@ -1,15 +1,13 @@ export function createElement({ innerText, textContent, onclick, onchange, children = [], dataset, style, classList = [], ...attributes }, tagName = 'div') { const element = document.createElement(tagName) - for (const key in attributes) { - element.setAttribute(key, attributes[key]) - } + for (const key in attributes) element.setAttribute(key, attributes[key]) if (style) Object.assign(element.style, style) if (classList.length) element.classList.add(...classList) - if (innerText) element.innerText = innerText if (textContent) element.textContent = textContent - if (onclick) element.onclick = onclick + if (innerText) element.innerText = innerText if (onchange) element.onchange = onchange - if (dataset) Object.keys(dataset).forEach(key => element.dataset[key] = dataset[key]) + if (onclick) element.onclick = onclick + if (dataset) Object.assign(element.dataset, dataset) if (children) children.forEach(child => element.appendChild(child)) return element }