gpt4 book ai didi

javascript - rails 6 : Uncaught Reference Error - $ is not defined

转载 作者:行者123 更新时间:2023-12-02 22:22:54 25 4
gpt4 key购买 nike

我正在尝试让语义 UI 按钮在 Rails 6 中使用 Javascript 工作。但是,我的代码都无法正常工作。代码如下所示:

$(document).on('turbolinks:load', function() {
$('.message .close').on('click', function() {
$(this).closest('.message').transition('fade');
})
;
})

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

我的应用程序 JS 文件如下所示:

// 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)

最佳答案

Uncaught ReferenceError: $ is not defined

此错误指出 $ 尚未声明,这最终表明 jquery 未正确加载到页面中

检查gemfile中是否添加了jquery gem

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

关于javascript - rails 6 : Uncaught Reference Error - $ is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59165827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com