From 3d8502d8ccfc85d709dd37a9344f148fda77467f Mon Sep 17 00:00:00 2001 From: * <8> Date: Wed, 26 Jan 2022 14:40:21 +0800 Subject: [PATCH] Match-id-75c2d0560e7b4ee729267dae97f85520e426bf6b --- libs/horizon/src/dom/utils/DomCreator.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libs/horizon/src/dom/utils/DomCreator.ts b/libs/horizon/src/dom/utils/DomCreator.ts index 360aea81..9d89ef5f 100644 --- a/libs/horizon/src/dom/utils/DomCreator.ts +++ b/libs/horizon/src/dom/utils/DomCreator.ts @@ -5,6 +5,13 @@ export const NSS = { svg: 'http://www.w3.org/2000/svg', }; +const div = document.createElement('div'); +const span = document.createElement('span'); +const tr = document.createElement('tr'); +const td = document.createElement('td'); +const a = document.createElement('a'); +const p = document.createElement('p'); + // 创建DOM元素 export function createDom( tagName: string, @@ -16,6 +23,18 @@ export function createDom( if (ns !== NSS.html) { dom = document.createElementNS(ns, tagName); + } else if (tagName === 'div') { + dom = div.cloneNode(false); + } else if (tagName === 'span') { + dom = span.cloneNode(false); + } else if (tagName === 'tr') { + dom = tr.cloneNode(false); + } else if (tagName === 'td') { + dom = td.cloneNode(false); + } else if (tagName === 'a') { + dom = a.cloneNode(false); + } else if (tagName === 'p') { + dom = p.cloneNode(false); } else { dom = document.createElement(tagName); }