RoR + Jquery无法正常工作 [英] RoR + Jquery not working

查看:74
本文介绍了RoR + Jquery无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的项目中使用jQuery.我知道javascript_include_tag会调用jQuery插件,但是<script type="text/javascript">标签如何在ruby中工作?

I want use jQuery in my project. I know the javascript_include_tag calls the jQuery plugins, but the <script type="text/javascript"> tag how does it work in ruby?

示例

<%= javascript_include_tag 'jquery.ui.potato.menu.js' %>
<%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js' %>

<script type="text/javascript">
(function($) {
        $(document).ready(function(){
                $('#menu1').ptMenu();
        });
})(jQuery);
</script>

这在RoR中不起作用

推荐答案

您需要反转脚本标签,如下所示:

You need to reverse your script tags, like this:

<%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js' %>
<%= javascript_include_tag 'jquery.ui.potato.menu.js' %>

需要先加载jQuery,然后 依赖jQuery的任何内容才能尝试运行,例如插件.

jQuery needs to be loaded before anything that depends on jQuery tries to run, e.g. plugins.

如果您刚刚开始,还可以考虑进行升级.如果您使用的插件支持该插件,则最新版本(截至本回答时)为 1.4.2 .

Also consider upgrading if you're just getting started. If the plugin you're using support it, the latest (as of the time of this answer) is 1.4.2.

这篇关于RoR + Jquery无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆