简体   繁体   中英

How to call javascript function from html tag in rails?

I have one js file which has one function and one html file from which i am calling that js function. I have done something and its able to find the path of js file but its not able to find function inside that js file. Any help pelase its very important? 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");
        }

The error is in your javascript_include_tag..

it should be:

<%= javascript_include_tag "graph" %>

Also.. ensure that graph.js is located in app/assets/javascripts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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