jquery 插件中的触发功能?

Fire function within jquery plugin?

我已经为某些 html 元素(特别是数字输入)动态创建了递增和递减按钮,但是我一辈子都不知道如何通过插件功能。

我想专门这样做,因为这些箭头将用于许多不同类型的表单,减去和添加值(例如 %、金钱等)会影响某些视觉元素。

函数查找以下行:

(function ($) {
    $.fn.addIncrementArrows = function (min, max, interval, fastInterval, event) {

        var input = this;

        /*Other building things go here*/

        var timeoutDownArrow;
        var intervalDownArrow;
        //clicking button down for 1 second fires '-' actions
        $(this).parent().children(".downarrow").mousedown(function () {
            timeoutDownArrow = setTimeout(function () {
                intervalDownArrow = setInterval(function () {
                    changeValue(-fastInterval);

                    //how to do event here?

                }, 90);
            }, 750);
        }).bind("mouseup mouseleave", function () {
            clearTimeout(timeoutDownArrow);
            clearInterval(intervalDownArrow);
        });

    };
}(jQuery));

简单地说就是我需要声明使其具有如下箭头:

formnamehere.addIncrementArrows(0, 100, 1, 5, event);

如果可能:我如何将动作绑定到 .addIncrementArrows() 中的按钮?

经过一番研究,我得出了一个结论:

1 - 在 .addIncrementArrows() 中将函数更改为 运行 作为命名的 运行-time 函数:

var setSliderPercentage = function (percent) {
    //do stuff here
}

2 - 将函数作为变量名传递到插件中

percentageForm.addIncrementArrows(0, 100, 1, 5, setSliderPercentage);

3 - 运行 addIncrementArrows() 插件中传递的函数。

$.fn.addIncrementArrows = function (min, max, interval, fastInterval, event) {
    var input = this;
    if (max === false) max = Infinity; //infinity and beyond!

    //Other stuff here

    //make the it auto increment or decrement every 100ms when 'holding down' the button after 1 second
    var timeoutUpArrow;
    var intervalUpArrow;
    $(uparrow).mousedown(function () {
        timeoutUpArrow = setTimeout(function () {
            intervalUpArrow = setInterval(function () {
                changeValue(fastInterval);
                //
                if (typeof event != "undefined") event(input.val());
                //
            }, 90);
        }, 750);
    }).bind("mouseup mouseleave", function () {
        clearTimeout(timeoutUpArrow);
        clearInterval(intervalUpArrow);
    });

}