【问题标题】:How can I override few parameter of plugin without editing it如何在不编辑的情况下覆盖插件的几个参数
【发布时间】:2016-01-26 22:34:52
【问题描述】:

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

【问题讨论】:

    标签: javascript jquery plugins jquery-plugins


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢迈克。但我无法进行任何更改/替换现有代码。必须使用外部代码覆盖此参数
    • @golekunal88 这是外部代码。你可以把它放在你的任何文件中。
    猜你喜欢
    • 2020-08-11
    • 2012-09-09
    • 2017-10-26
    • 2012-11-02
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    • 2019-06-13
    • 1970-01-01
    相关资源
    最近更新 更多