javascript - 使用 Aurelia 动态渲染 html

标签 javascript jquery html aurelia

我有一个要求,我以 HTML 标记的形式获取字符串,并在单击按钮时更改它。单击按钮时,我正在更改绑定(bind)元素的值。

<div id="htmString">${htmlTag}</div>

而htmlTag中的内容是

<p>Hello World!</p>

如何跳过在 View 模型中编写 document.getElement 并仍然编译 HTML。

最佳答案

您只需要像这样绑定(bind)到 innerHTML 属性: <div id="htmString" innerhtml.bind="htmlTag"></div>

因此,只要 htmlTag 发生变化,它就会呈现在您的 div 中。

关于javascript - 使用 Aurelia 动态渲染 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39138374/

相关文章:

javascript - 当按钮从 ajax 调用时,jquery 不起作用

javascript - ajax成功延迟不起作用

c# - 使用 Controller 返回的值填充图表

javascript - 仅用 javascript css 和 html 编写的可编辑表格

css - 在 div 中居中文本

javascript - 如何通过<th>值获取表<td>内容

javascript - 突出显示元素中的子字符串

javascript - 使用 jQuery 下拉 ul li

javascript - "SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 295 of the JSON data"

jquery - span 按钮顶部的 click() 不起作用