2014-01-28 36 views
1

我試圖使用的jCarousel和被扔在頁面加載時,它拋出這個錯誤..的JavaScript運行時錯誤而使用的jCarousel

JavaScript runtime error: Object doesn't support property or method 'jcarousel' 

和我帶到了這個功能...

(function($) { 
$(function() { 
    $('[data-jcarousel]').each(function() { 
     var el = $(this); 
     el.jcarousel(el.data()); 
    }); 

    $('[data-jcarousel-control]').each(function() { 
     var el = $(this); 
     el.jcarouselControl(el.data()); 
    }); 
}); 
})(jQuery); 

錯誤在第五行。

這裏是我的標記......

<div class="wrapper"> 
     <div class="jcarousel-wrapper"> 
      <div data-jcarousel="true" data-wrap="circular" class="jcarousel"> 
       <ul> 
        <li><img src="images/1.png" width="600" height="400" alt=""></li> 
        <li><img src="images/2.png" width="600" height="400" alt=""></li> 
        <li><img src="images/3.png" width="600" height="400" alt=""></li> 
        <li><img src="images/4.png" width="600" height="400" alt=""></li> 
       </ul> 
      </div> 
      <a data-jcarousel-control="true" data-target="-=1" href="#" class="jcarousel-control-prev">&lsaquo;</a> 
      <a data-jcarousel-control="true" data-target="+=1" href="#" class="jcarousel-control-next">&rsaquo;</a> 
     </div> 
    </div> 

,這裏是我的頭腳本...

<meta charset="utf-8" /> 
<title></title> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script> 
<link rel="stylesheet" href="http://localhost:3108/code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> 
<link rel="stylesheet" href="/resources/demos/style.css"> 

<script src="jquery-1.10.2.min.js"></script> 
<script src="jcarousel.data-attributes.js"></script> 

我試圖只是把函數本身在頭標籤,它仍然拋出一個錯誤。我已經在這方面尋找答案,沒有具體的問題。

感謝

回答

0

我當然不是的jCarousel的專家,但我沒有看到,你actually include it

我看到的東西,看起來像一個插件吧:

<script src="jcarousel.data-attributes.js"></script> 

但我希望看到在此之前,實際jCarousel腳本:

<script type="text/javascript" src="jquery.jcarousel.js"></script> 

UPDATE:

我的意思是,爲了完成這項工作,您需要完整的腳本列表:

<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="jquery.jcarousel.js"></script> 
<script type="text/javascript" src="jcarousel.data-attributes.js"></script> 

你需要包含jQuery,你已經做了。 您還需要包含jCarousel,您目前沒有。你只需要在數據屬性插件之前加入這個插件就可以使所有的東西都可以工作。

+0

我很新,jquery和使用插件,當我下載jCarousel它帶有示例,當我嘗試運行我要修改的示例時,它不會運行,因爲它是說jQuery是沒有定義的。所以我試着重寫這個例子,並得到了我提到的錯誤。我只想找到一個腳本,我可以用它來做一個簡單的幻燈片顯示next和prev導航,我可以用asp.net做到這一點,但是當移動到下一個圖像時會有點搖晃。 jQuery似乎更順暢,不需要回發 – Chris

+0

我添加了文本/ javascript類型,但它拋出了相同的錯誤。 – Chris

+0

這不是真的問題。您需要確保包含jCarousel腳本。我會更新答案,以便更清楚。 – Josh