[英]How to use jQuery in Rails
I did not manage to use jquery in rails Here the necessary files 我没有在rails中使用jquery在这里必要的文件
in the head of application layout, I have
在应用程序布局的负责人中,我有
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
application.js has
application.js有
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .
box.js has
box.js有
$(document).ready(function() {
$(".box").click(function(){
$(this).fadeOut("fast");
});
box.html.erb
box.html.erb
<div class="box"></div>
Box have necessary height,width,bg-color vs in css file. 盒子在css文件中有必要的高度,宽度,bg颜色。 I just want the box fade out when I click but I don't know what I did wrong.
我只希望单击时淡出该框,但不知道自己做错了什么。 I also have the jquery-rails gem in the gemfile
我在gemfile中也有jquery-rails gem
The problem is the class name, and nothing to do with Rails. 问题是类名,与Rails无关。
Swap; 交换;
<div class=".box"></div>
To; 至;
<div class="box"></div>
Because .box
is just another syntax for saying "the HTML element with the class of box
". 因为
.box
只是说“带有box
类的HTML元素”的另一种语法。
Add jQuery Ui in your project and then check. 在您的项目中添加jQuery Ui,然后检查。 For effects and animations you need to have jQuery UI.
对于效果和动画,您需要使用jQuery UI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.