【问题标题】:Get the HTML content of a template Meteor获取模板 Meteor 的 HTML 内容
【发布时间】: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


    【解决方案1】:

    您可以为此使用JQuery(已内置在流星中)

    var html = $('#example').html();
    

    【讨论】:

      【解决方案2】:

      从 Meteor 1.x 开始,您可以使用 Blaze.toHTML()。它以字符串形式返回给定模板的 HTML。

      【讨论】:

        【解决方案3】:

        如果您使用 Template.test.events 分配点击事件,您应该在“this”中拥有模板描述的所有数据。

        【讨论】:

          猜你喜欢
          • 2015-05-27
          • 2015-10-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-11-17
          • 1970-01-01
          • 2014-12-12
          • 2017-09-16
          相关资源
          最近更新 更多