。著名的東西
的Rails 4.1.8
的jQuery 3.1.3軌道
Windows 7的
我目前想在應用程序運行一個簡單的coffescript/assets/javascripts/login.jscoffe
# login.js.coffee #
$(document).on "page:change", ->
$('#loginb').click ->
alert "Clicked!"
當我加載頁面時,我得到一個控制檯錯誤。
Uncaught reference error $ is not defined
現在我已經嘗試了幾件事情,比如使用rake預編譯。確保我包含在下面的應用程序js中。
//= require jquery
//= require jquery_ujs
我一直在閱讀,看看是否有其他解決方案。有些人在談論渦輪鏈接。我應該只包含jquery權限到html頁面嗎?
included jquery?No I have not。 – MooCow
require語句已添加上面 – MooCow
我可以建議調查問題。首先,通過執行「Ctrl + u」或「view pagesource」來檢查你的源代碼頁是否加載jQuery文件。如果成功加載,請嘗試使用'jQuery'而不是'$'符號。如果它有效,我們認爲其他JS庫與您的應用程序中的jQuery衝突。 –