首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Rails 6:未定义未定义的参考错误-$

Rails 6:未定义未定义的参考错误-$
EN

Stack Overflow用户
提问于 2019-12-03 21:45:02
回答 2查看 2.5K关注 0票数 2

我试图在Rails 6中使用Javascript来获得一个语义UI按钮,但是,我的代码都没有正常工作。代码如下所示:

代码语言:javascript
运行
复制
$(document).on('turbolinks:load', function() {
   $('.message .close').on('click', function() {
   $(this).closest('.message').transition('fade');
   })
;
})

我得到的错误是:未定义的ReferenceError:$。

我的应用程序JS文件看起来如下:

代码语言:javascript
运行
复制
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
// Loads all Semantic javascripts
//= require jquery
//= require semantic-ui
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require_tree .
// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-12-03 21:54:43

代码语言:javascript
运行
复制
Uncaught ReferenceError: $ is not defined

这个错误引用还没有声明$,这最终表示jquery没有正确加载到页面中。

检查是否将jquery添加到gem文件中。

另外,尝试是否使用jQuery作为标识符而不是使用$

票数 0
EN

Stack Overflow用户

发布于 2019-12-04 04:30:12

在html页面中添加jquery支持文件。

代码语言:javascript
运行
复制
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59165827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档