如何在不编辑的情况下覆盖插件的几个参数



想要在不编辑的情况下覆盖插件的几个参数。 插件链接 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>

你可以用你自己的函数替换它:

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);
};

最新更新