jQuery在Rails 3.2.8上不起作用 [英] jQuery not working on Rails 3.2.8
问题描述
我在Rails 3.2.8上遇到了jQuery问题.我已经安装了jquery-rails gem,并且我的application.js具有以下内容:
I'm having an issue with jQuery on Rails 3.2.8. I've installed the jquery-rails gem and my application.js has the following:
//= require jquery
//= require jquery_ujs
//= require_tree .
views/layouts/application.html.erb具有
views/layouts/application.html.erb has
<%= javascript_include_tag "application" %>
test.js中的简单Javascript测试:
A simple Javascript test in test.js:
if (jQuery) {
alert('Jquery is loaded')
} else {
alert ('Jquery is not loaded')
}
给了我一个警报,告诉我确实确实加载了jQuery.
gives me an alert telling me that jQuery is indeed loaded.
但是,没有jQuery命令可以使用,即使基本的命令也没有响应:
However, no jQuery commands will work, even basic ones are unresponsive:
$(document).ready(function(){
$("a").click(function(event){
alert("Thanks for visiting!");
});
});
我已经尝试了所有方法-甚至通过Google API包括了jQuery.关于可能发生的事情有什么想法吗?
I've tried everything -- even reincluding jQuery through the Google API. Any ideas on what might be going on?
推荐答案
已修复!
在application.html.erb中,我从以下位置更改了这两行的顺序:
in application.html.erb, I changed the ordering of these two lines from:
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
收件人:
<%= javascript_include_tag "application" %>
<%= stylesheet_link_tag "application", :media => "all" %>
现在可以使用了!我不太确定为什么会有人解释?
Now it works! I'm not quite sure why though, can anybody explain?
这篇关于jQuery在Rails 3.2.8上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!