这是我的 CoffeeScript
$(document).on "turbolinks:load", ->
$('#comments-link').click ->
$('#comments-section').toggle()
这是我的 .scss 文件
#comments-section{
display: none;
}
她的是 HTML 文件
<%= link_to 'Comments','#', id: "comments-link"%>
<div id="comments-section">
<%= render @recipe.comments %>
</div>
当我点击链接时,没有任何反应。 在 Web 控制台中,代码可以正常运行,没有任何错误。 有什么建议
最佳答案
好吧,我发现我必须阻止Default()
$('#comments-link').click (e)->
e.preventDefault()
关于javascript - Turbolinks Rails 5 切换事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43505471/