【问题标题】:Html comment breaking the websitehtml评论破坏网站
【发布时间】:2015-12-01 08:09:16
【问题描述】:

单击另一个页面的链接后,我收到“无法在 'Node' 上执行 'insertBefore'”错误:

<template name="reminderPage">
    <a href="/newRemind">New!</a>
    {{>reminder}}
    <!-- Random comment -->
</template>

<template name="reminder" class="reminder">
      <p>Hello reminder</p>
        {{>editForm}}
</template>

<template name="editForm">
    <div id="dialog-form" title="Edit Reminder">
      <p class="validateTips">All form fields are required.</p>
      <form>
        <fieldset>
          <label for="taskf-name">Name</label>
          <input type="text" name="taskf-name" id="taskf-name" maxlength="20">
          <label>Bought</label>
          <input type="text" name="taskf-bought" id="taskf-bought">
          <label>Expire</label>
          <input type="text" name="taskf-expire" id="taskf-expire">
        </fieldset>
      </form>
    </div>
</template>

显然,那个小注释干扰了代码,因为在我删除它之后,一切都运行良好。

虽然问题得到了解决,但我真的很想知道这条线是如何妨碍代码的。

有人知道为什么吗?我在 Iron-Router 上使用 Meteor。

谢谢!

编辑

如果有帮助,我正在使用 Jquery-UI,这是我的 javascript 文件

Template.reminder.rendered = function () {

  $( "#dialog-form" ).dialog({
    autoOpen: false,
    modal: true,
    open: function () {
    },
    buttons: [
        {
          id: "button-ok",
          text: "Save",
          click: function() {
              $(this).dialog("close");
          }
        },
        {
          id: "button-cancel",
          text: "Cancel",
          click: function() {
              $(this).dialog("close");
          }
        }
    ]
  });

}

“newRemind”页面只有最基本的对话框,它的js文件只是启动它。

<template name="newRemindPage">
    <div id="dialog" title="Basic dialog">
      <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
    </div>
</template>

Javascript:

Template.newRemindPage.rendered = function () {
  $( "#dialog" ).dialog();
};

【问题讨论】:

  • 必须是你的 Iron-Router 的东西,模板内的 cmets 不会造成任何副作用。这是证据:jsfiddle.net/b4f9wwt8
  • 尝试使用空格键 cmets 而不是 HTML cmets:{{!-- COMMENT --}}
  • 这有点奇怪。经过更多测试,破坏网站的是那些对话框。如果我删除其中一个,评论可以保留,但如果同时保留,当评论出现时应用程序崩溃。此外,如果我更改没有被标签包围的任何内容(例如随机文本)的评论,应用程序崩溃,但如果我标记它,它可以工作
  • 更改hello 的评论会破坏页面,但&lt;p&gt;hello&lt;/p&gt; 不会。空格键 cmets 也会打破它。 @saimeunt

标签: javascript html jquery-ui meteor iron-router


【解决方案1】:

Spacebars documentation on comments:

{{! Comments can be one line}}

{{!
  Or they can be
  multi-line
}}

{{!-- They can also be written like this --}}

如果尝试此操作后不起作用,请发布您的更新代码。

【讨论】:

  • 用其中任何一个替换评论仍然会使网站崩溃。它们工作的唯一方法(或标准的 html cmets)是如果我用 div 包围它们。 {{!-- They can also be written like this --}} 崩溃。 &lt;div&gt;{{!-- They can also be written like this --}}&lt;/div&gt; 不会崩溃。
  • 您可能希望将问题发布到 repo 以防这是一个错误:github.com/meteor/meteor/issues
  • 好的。我真的不想发布它,因为我认为这是 Jquery-ui 的错。该网站有两个对话框(每页一个),当任何一个被删除时,它都可以正常工作。非常感谢您的帮助!
猜你喜欢
  • 2010-12-07
  • 1970-01-01
  • 2016-08-22
  • 2011-07-09
  • 1970-01-01
  • 1970-01-01
  • 2014-12-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多