2015-11-10 34 views
1

我試圖在中間人使用鍵入的js,我不能得到它的工作。鍵入js不工作在中間人

在index.html.erb

<span class="elementTyped"></span> 

在all.js

//= require_tree . 
//= require jquery 
//= require bootstrap-sprockets 

<script src="jquery.js"></script> 
<script src="typed.js"></script> 
<script> 
    $(function(){ 
     $(".elementTyped").typed({ 
      strings: ["My name is example", "I am a developer"], 
      typeSpeed: 0 
     }); 
    }); 
</script> 

佈局

<%= javascript_include_tag "all" %> 

即時結算做錯了,https://jsfiddle.net/uw9uqc30/1/

回答

0

主要是你的問題是你有一個JavaScript文件中的HTML。您的<script>標籤爲html。如果你看看你鏈接的jsfiddle,你會發現這些標籤在HTML窗格中,沒有javascript窗格。從all.js中刪除它們。

其次Rails使用另一種方式來鏈接資源。您在all.js的頂部看到那些//= require陳述?已有一個用於jquery.js,您只需添加一個用於typed.js