简体   繁体   中英

Javascript code not working in Ruby on Rails

I was trying to do my front-end with this Codepen Template but when i'm trying to click on the signup button, it's not changing to signup form for which the code is in the index.js file, i've included hte index.js file in the login.html.erb but when i'm running the rails server the transition isn't working. My Rails Project , Codepen Template Here is the javascript code in index.js

document.querySelector('.img__btn').addEventListener('click', function() {
document.querySelector('.cont').classList.toggle('s--signup');  });

尝试更改index.js的路径。在app.html中添加此行以包含index js文件。

<%= javascript_include_tag "index" %>

Wrap your current JS code in app/assets/javascripts/application.js within a DOMContentLoadListener event listener :

document.addEventListener('DOMContentLoaded', function() {
  document.querySelector('.img__btn').addEventListener('click', function() {
    document.querySelector('.cont').classList.toggle('s--signup');
  });
});

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