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