2016-01-26 40 views
0

想要覆蓋插件的幾個參數而不編輯它。鏈接插件https://www.o2.co.uk/shop/homepage/images/shop15/carousel/js/carousel.jquery.js我們可以添加另一個腳本來覆蓋上面的腳本對象參數,如displayTime到1000 & autoStart爲false。 。我試過$ .extend()。但失敗了。我並不想在當前插件的變化如何在不編輯它的情況下覆蓋插件的幾個參數

<script> 

(function($,document,undefined) { 
$.fn.carousel = function(opts) { 
var options = { 
    'displayTime': 5000, 
    'autoStart': true 
}; 

<----code ---> 
} 
</script> 

回答

0

你可以用自己的函數替換它:

var oldCarousel = $.fn.carousel; // Need a reference to the original 
$.fn.carousel = function(opts) { 
    var options = { 
    // set your personal defaults here 
    }; 
    if (opts) { 
    $.extend(options, opts); 
    } 
    return oldCarousel.call(this, opts); 
}; 
+0

感謝麥克。但我不能做任何改變/替換現有的代碼。必須使用外部代碼覆蓋此參數 – golekunal88

+0

@ golekunal88這是外部代碼。你可以把它放在你的任何文件中。 –

相關問題