Javascript 为插件创建自定义事件
我想知道如何为我的插件创建自己的自定义事件,以及如何触发事件。我的addItem函数可以工作,但我不知道如何使自己的自定义事件工作,有人知道吗Javascript 为插件创建自定义事件,javascript,jquery,Javascript,Jquery,我想知道如何为我的插件创建自己的自定义事件,以及如何触发事件。我的addItem函数可以工作,但我不知道如何使自己的自定义事件工作,有人知道吗 $('#TreeView').Web().DropDownList().onload(function () { alert('loaded function event'); }).click(function () { $(this).addItem('Hello World'); }); $.fn.Web = function (
$('#TreeView').Web().DropDownList().onload(function () {
alert('loaded function event');
}).click(function () {
$(this).addItem('Hello World');
});
$.fn.Web = function () {
var $this = this;
return {
TreeView: function () {
return $this.each(function () {
alert('TreeViewControl');
})
},
DropDownList: function () {
var methods = {
addItem: function () {
alert('AddItem');
}, removeItem: function () {
alert('removeItem');
}
}
return $this.each(function () {
//methods.addItem.apply(this, arguments);
for (var method in methods) {
methods[method].apply(this, arguments);
}
return this;
})
}
}
};