为插件创建自定义事件

时间:2011-12-03 03:47:50

标签: javascript jquery

我想知道如何为我的插件创建自己的自定义事件以及如何触发事件。我的addItem函数有效,但我不知道如何使我自己的自定义事件工作有人知道吗?

$('#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;
            })
        }
    }
};

0 个答案:

没有答案
相关问题