功能的附加值

时间:2018-04-24 07:39:30

标签: jquery merge push

如何在函数中添加其他值?推或合并?

jQuery('#col_6907134').cycle({fx: 'fade', speed: 1000, timeout: 6500});

Values:
prev: '#prev'
next: '#next'

2 个答案:

答案 0 :(得分:0)

您可以使用extend加入多个json对象

$(function(){

    var default_values = {fx: 'fade', speed: 1000, timeout: 6500};
    var new_values = {
        prev : '#prev',
        next : '#next',
    };    
    var extended = $.extend( default_values, new_values );

    jQuery('#col_6907134').cycle(extended);

});

答案 1 :(得分:0)

此代码创建上述功能:

$.fn.cycle = function(options, arg2) {
var o = { s: this.selector, c: this.context };

// in 1.3+ we can fix mistakes with the ready state
if (this.length === 0 && options != 'stop') {
    if (!$.isReady && o.s) {
        log('DOM not ready, queuing slideshow');
        $(function() {
            $(o.s,o.c).cycle(options,arg2);
        });
        return this;
    }
    // is your DOM ready?  http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
    log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
    return this;
}

// iterate the matched nodeset
return this.each(function() {
    var opts = handleArguments(this, options, arg2);
    if (opts === false)
        return;

    opts.updateActivePagerLink = opts.updateActivePagerLink || $.fn.cycle.updateActivePagerLink;

    // stop existing slideshow for this container (if there is one)
    if (this.cycleTimeout)
        clearTimeout(this.cycleTimeout);
    this.cycleTimeout = this.cyclePause = 0;
    this.cycleStop = 0; // issue #108

    var $cont = $(this);
    var $slides = opts.slideExpr ? $(opts.slideExpr, this) : $cont.children();
    var els = $slides.get();

    if (els.length < 2) {
        log('terminating; too few slides: ' + els.length);
        return;
    }

    var opts2 = buildOptions($cont, $slides, els, opts, o);
    if (opts2 === false)
        return;

    var startTime = opts2.continuous ? 10 : getTimeout(els[opts2.currSlide], els[opts2.nextSlide], opts2, !opts2.backwards);

    // if it's an auto slideshow, kick it off
    if (startTime) {
        startTime += (opts2.delay || 0);
        if (startTime < 10)
            startTime = 10;
        debug('first timeout: ' + startTime);
        this.cycleTimeout = setTimeout(function(){go(els,opts2,0,!opts.backwards);}, startTime);
    }
});

};

结果:

jQuery('#col_6907134').cycle({fx: 'fade', speed: 1000, timeout: 6500});

如何在不更改上限代码的情况下通过函数添加其他值:

    var new_values = {
    prev : '#prev',
    next : '#next',
};