繁体   English   中英

如何从Rails中的html标签调用javascript函数?

[英]How to call javascript function from html tag in rails?

我有一个具有一个功能的js文件和一个从中调用该js函数的html文件。 我已经做了一些事情,它能够找到js文件的路径,但无法找到该js文件中的函数。 任何帮助都说明其非常重要吗? index.html.erb

<html>
 <html>
   <head>
   <%= javascript_include_tag "graph.js" %>
   </head>
   <body>
   <input type="button" onclick="popup()" value="Click Me!">
     <p>Hello!</p>
   </body>
 </html>

graph.js

 function popup()
        {
        alert("some text");
        }

错误出现在您的javascript_include_tag中。

它应该是:

<%= javascript_include_tag "graph" %>

另外..确保graph.js位于app / assets / javascripts中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM