使用 coffeescript 在 rails 4 中的元素上制作 popover bootstrap

Make popover bootstrap on element in rails 4 with coffeescript

我正在尝试在 rails 中的 apple 元素上添加 onclick 事件。这是 coffeescript。

apple.on 'click', () ->
  $(this).popover('[data-content="This is the body of Popover"]');

我怎样才能让它发挥作用?

您应该检查网页上的元素并检查控制台以查看是否存在任何 JS 错误。我认为你也应该适当地引用 'apple'。例如:

$('#apple').on 'click', () ->
  $(this).popover('[data-content="This is the body of Popover"]');

我本来可以将此添加为评论,但我没有足够的代表。让我知道你过得怎么样。

我把 HTML data attributeJS attribute 混在一起了。所以正确答案是这样的。

$('#apple').on 'click', () ->
      $(this).popover({content = "This is the body of Popover"};