将简单的模态库添加到rails app

时间:2012-11-12 05:51:16

标签: javascript ruby-on-rails

我想将Simple modal javascript库添加到我的rails应用

在网页上,所有js文件都已成功加载

<script src="/assets/simple-modal/mootools-core-1.3.1.js?body=1" type="text/javascript"></script>
<script src="/assets/simple-modal/mootools-more-1.3.1.1.js?body=1" type="text/javascript"></script>
<script src="/assets/simple-modal/simple-modal.js?body=1" type="text/javascript"></script>

我尝试在咖啡中添加这样的事件:

$(document).ready ->
  $("#batch a.accept").live 'click', ->
    SM = new SimpleModal(btn_ok: "Alert button")
    SM.show
      title: "Title"
      contents: "Your message..."

这个代码在firebug控制台中得到了

TypeError: $("simple-modal").getElement is not a function

当我尝试使用javascript添加事件时,如手册:

window.addEvent("domready", function(e){
/* Alert */
$("#batch a.accept").addEvent("click", function(e){
  e.stop();
  var SM = new SimpleModal({"btn_ok":"Alert button"});
      SM.show({
        "title":"Alert Modal Title",
        "contents":"Lorem ipsum dolor sit amet..."
      });
});
});

我收到了这个错误:

TypeError: $("#batch a.accept").addEvent is not a function

我该怎么办?

1 个答案:

答案 0 :(得分:0)

尝试将jquery添加到脚本列表的顶部

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="/assets/simple-modal/mootools-core-1.3.1.js?body=1" type="text/javascript"></script>
<script src="/assets/simple-modal/mootools-more-1.3.1.1.js?body=1" type="text/javascript"></script>
<script src="/assets/simple-modal/simple-modal.js?body=1" type="text/javascript"></script>