2
我想写一个自动完成的jQuery插件。添加方法链接在jQuery插件
期望使用:
$('.advancedSelect').advancedSelect({/*plugin options*/}).change(function(){})/*.otherJQueryMethods*/;
实施:
$.fn.advancedSelect = function({
return this.each(function(){
var $advSel = $('<input/>');
var $el = $(this).after($advSel).hide();
/* my codes on desired functionalities */
/* how is it possible to trigger the chained change method */
});
});
对自定义的'adv.change'事件和'trigger('adv.change')'使用'on'可能是案例的最佳选择。代码将如下所示: 我想你在说什么是在那里(如果有的话)没有办法实现上述语法,对吧? – hbtb 2015-01-04 19:22:43
@hbtb:没有合理的方式,没有。我的意思是,你可以在你的插件函数中做到这一点:'this.onChange = function(){...};'(例如,为一个jQuery对象*添加一个函数),但我不会说合理。我一定会用你自己的活动名称并使用'on'。 – 2015-01-04 19:28:02