我有这个代码:
<% @hello = "hello world" %>
<td class="text"><%= link_to project.name, project,
:onmouseout=>"hidetooltip()",
:onmouseover=>"showDescription()"%>
</td>
showDescription
JavaScript 函数采用字符串参数。我想将 @hello
作为参数传递给 showDescription
。我尝试了一切,但似乎无法让它发挥作用。
最佳答案
给你:
<% @hello = "hello world" %>
<%= link_to project.name, project, :onmouseout=>"hidetooltip()",
:onmouseover=>"showDescription(#{ @hello.to_json })"%>
关于javascript - 是否可以将 Rails 变量传递到 JavaScript 函数中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8006528/