我正在使用 javascript 模板构建一小段 html 文档。const button
下面的代码是我的模板。如您所见,我使用替换替换了一些内容。const button
成为<button>label</button>
,这很好。
const button = `<button>{try}</button>`;
const newButton = button.replace('{try}', 'label');
const body = document.querySelector('body');
现在我想在 body 标签内附加我的 bew 按钮。
body.append(newButton);
它可以工作,但是当我刷新浏览器时,我看到“ <button>label</button>
”,但我想要这个 html 的渲染版本,现在我看不到一个按钮,只有一个字符串<button>...
。如何渲染此按钮?