【发布时间】:2015-05-02 06:08:45
【问题描述】:
如何获取模板的 html 内容?例如,我有以下模板:
<template name="test">
<div id="example">
<strong>This is a test.</strong>
</div> <button id="btn">Get</button></template>
我需要捕获 div # 示例的 HTML 内容的按钮事件单击。有可能吗?
【问题讨论】:
标签: meteor
如何获取模板的 html 内容?例如,我有以下模板:
<template name="test">
<div id="example">
<strong>This is a test.</strong>
</div> <button id="btn">Get</button></template>
我需要捕获 div # 示例的 HTML 内容的按钮事件单击。有可能吗?
【问题讨论】:
标签: meteor
您可以为此使用JQuery(已内置在流星中)
var html = $('#example').html();
【讨论】:
从 Meteor 1.x 开始,您可以使用 Blaze.toHTML()。它以字符串形式返回给定模板的 HTML。
【讨论】:
如果您使用 Template.test.events 分配点击事件,您应该在“this”中拥有模板描述的所有数据。
【讨论】: