2016-04-18 4 views
0

実際には私はヘッドに触れることができないCMSで作業しています。本体にコンテンツを挿入するだけで、JSライブラリは実際に読み込まれます。JSを使わずにJS(本体のみ)

<script></script>タグのコードクローンからスクリプトを挿入しようとしましたが、うまくいかなかったようです。

エラー:

Uncaught ReferenceError: CBPFWTabs is not defined apercu-335.kjsp:1125 Uncaught SyntaxError: Unexpected end of input

<body>内のコード:

<script> 
    (function() { 
      [].slice.call(document.querySelectorAll('.tabs')).forEach(function(el) { 
       new CBPFWTabs(el); 
      }); 

     })(); 
</script> 

<script> 
    (function(window) { 
     'use strict'; 
    function extend(a, b) { 
     for(var key in b) { 
      if(b.hasOwnProperty(key)) { 
       a[key] = b[key]; 
      } 
     } 
     return a; 
    } 

    function CBPFWTabs(el, options) { 
     this.el = el; 
     this.options = extend({}, this.options); 
     extend(this.options, options); 
     this._init(); 
    } 

    CBPFWTabs.prototype.options = { 
     start : 0 
    }; 

    CBPFWTabs.prototype._init = function() { 
     // tabs elems 
     this.tabs = [].slice.call(this.el.querySelectorAll('nav > ul > li')); 
    // content items 
    this.items = [].slice.call(this.el.querySelectorAll('.content-wrap > section')); 
    // current index 
    this.current = -1; 
    // show current content item 
    this._show(); 
    // init events 
    this._initEvents(); 
}; 

CBPFWTabs.prototype._initEvents = function() { 
    var self = this; 
    this.tabs.forEach(function(tab, idx) { 
     tab.addEventListener('click', function(ev) { 
      ev.preventDefault(); 
      self._show(idx); 
     }); 
    }); 
}; 

CBPFWTabs.prototype._show = function(idx) { 
    if(this.current >= 0) { 
     this.tabs[ this.current ].className = this.items[ this.current ].className = ''; 
    } 
    // change current 
    this.current = idx != undefined ? idx : this.options.start >= 0 &&  
this.options.start < this.items.length ? this.options.start : 0; 
    this.tabs[ this.current ].className = 'tab-current'; 
    this.items[ this.current ].className = 'content-current'; 
    }; 

    // add to global namespace 
    window.CBPFWTabs = CBPFWTabs; 
})(window);</script> 

ソース: http://tympanus.net/codrops/

はありがとうあなたの時間のために非常に。

答えて

0

エラーUnexpected end of inputは、コードに構文エラーがあることを意味します。修理する。

サイドノート

あなたは限り、あなたはそれをロードする前に、どこでも、これらの機能を使用しないよう<body>の終わりにあなたのコードを含めることができます。

は動作します:

<script src="jquery"></script> 
<script>$(document).ready();</script> 

を動作しません。

<script>$(document).ready();</script> 
<script src="jquery"></script> 
+0

あなたの答えをありがとう、私はコードをダブルチェックし、私は今なぜ知っていると思う。 – Warry

+1

@ワリー何が間違っているのかわかったら、教えてください。 – Justinas

0

を、私は問題を見つける必要があり、あなたの助けのために皆に感謝します。

ページが保存されると、CMSはコードをインラインで表示したので、コードの最初の "//"の後に次の行がナビゲータによってコメントとして扱われました。

私はコードからすべてのコメントを削除しました。問題はコード内ではなく、コードの一部が使用されていなかったためです。

ありがとうございました。

関連する問題