我在头部加载了jQuery插件,
然后在DOM就绪时运行该函数,
但是,我总是得到TypeError: $(...).jSlots is not a function
%head
= javascript_include_tag "application"
%script{charset: "utf-8", src: asset_path("jslot/jquery.jSlots.js"), type: "text/javascript"}
(function($){
$.jSlots = function(el, options){
~~~
$(document).ready ->
$('.fancy .slot').jSlots
number : 1,
winnerNumber : 1,
spinner : '#playFancy',
easing : 'easeOutSine',
time : 7000,
loops : 6,
onStart:
->
$('.slot').removeClass('winner')
onWin:
(winCount, winners) ->
$.each winners, ->
@addClass "winner"
return
if winCount==1
console.log "hi"
else if winCount > 1
console.log "hi"
return
答案 0 :(得分:0)
似乎你不包括jquery本身!
试试这个:
%head
= javascript_include_tag "application"
%script{charset: "utf-8", src: "http://code.jquery.com/jquery-1.11.1.js", type: "text/javascript"}
= javascript_include_tag "application"
%script{charset: "utf-8", src: asset_path("jslot/jquery.jSlots.js"), type: "text/javascript"}
我不是一个红宝石devlopper,不使用HAML,随时纠正答案。