Javascript jquery插件中的Fire函数?
我已经为某些html元素(特别是数字输入)动态创建了递增和递减按钮,但是我一辈子都无法弄清楚如何通过插件函数绑定动作 我想特别这样做,因为这些箭头将用于许多不同类型的表单上,这些表单会影响某些视觉元素的加减值(例如%、货币等) 该函数查看以下行:Javascript jquery插件中的Fire函数?,javascript,jquery,events,plugins,bind,Javascript,Jquery,Events,Plugins,Bind,我已经为某些html元素(特别是数字输入)动态创建了递增和递减按钮,但是我一辈子都无法弄清楚如何通过插件函数绑定动作 我想特别这样做,因为这些箭头将用于许多不同类型的表单上,这些表单会影响某些视觉元素的加减值(例如%、货币等) 该函数查看以下行: (function ($) { $.fn.addIncrementArrows = function (min, max, interval, fastInterval, event) { var input = this;
(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()作为命名运行时函数:
var setSliderPercentage = function (percent) {
//do stuff here
}
2-将函数作为变量名传递到插件中
percentageForm.addIncrementArrows(0, 100, 1, 5, setSliderPercentage);
3-在addIncrementArrows()插件中运行传递的函数
在插件函数中添加1个参数(元素、最小值、最大值、间隔、快速间隔、事件)。然后像$.addIncrementArrows($('formnamehere')、0、100、1、5、event那样使用它;添加您的html代码,以便创建示例或创建fiddlehow,在没有按钮“附加”的情况下如何使用此附加??在这里,您想在click事件上附加按钮,然后在内部插件函数中如何将其作为按钮引用?该按钮是在.addIncrementArrows()jQuery(“”.insertAfter(输入)中创建的;
$.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);
});
}