2014-07-09 40 views
0
上的母版

jQuery的自定義函數不工作jQuery的母版的自定義功能

我有一個自定義功能類似如下:

(function ($) { 
    $.fn.scrollingCarousel = function (options, i) { 
     ...something something 
    }; 

    jQuery.fn.scrollingCarousel.defaults = { 
     autoScroll: false, 
     autoScrollDirection: 'left', 
     autoScrollSpeed: 10000, 
     looped: false, 
     scrollerAlignment: 'horizontal', 
     scrollerOffset: 0, 
     scrollSpeed: 'fast', 
     beforeCreateFunction: null, 
     afterCreateFunction: null 
    }; 
})(jQuery); 

我在其中有一個母版頁使用它。 我在頁面中使用它如下。

<script type="text/javascript"> 
    $(document).ready(function() { 
     $(this).('#carousel-demo1').scrollingCarousel(); 
    }); 
</script> 

我得到一個錯誤,因爲scrollingCarousel無法識別。

如果我不使用masterpage代碼工作正常。

+0

這將真正幫助,如果你真的問了一個問題......你得到意想不到的行爲(scrollingCarousel不被認可)。什麼是錯誤?你有什麼需要幫助的?你有沒有包含適當的插件? – unclekyky

+0

'$(this)。('#carousel-demo1')'用法不正確 – spiderman

+0

1.您可以分享$ .fn.scrollingCarousel的代碼嗎? 2.根據@prash,$(this)。('#carousel-demo1')。scrollingCarousel();是不正確的。你的意思是$('#carousel-demo1')。scrollingCarousel();? – harsimranb

回答

0

如前所述,您所呼叫的功能的方式是不正確的

用法示例:

$(document).ready(function(){ 
var a = $("#carousel-demo1").scrollingCarousel(); 
}); 

(function ($) { 
    $.fn.scrollingCarousel = function (options, i) { 
     alert('something') 
    }; 

    jQuery.fn.scrollingCarousel.defaults = { 
     autoScroll: false, 
     autoScrollDirection: 'left', 
     autoScrollSpeed: 10000, 
     looped: false, 
     scrollerAlignment: 'horizontal', 
     scrollerOffset: 0, 
     scrollSpeed: 'fast', 
     beforeCreateFunction: null, 
     afterCreateFunction: null 
    }; 
})(jQuery);