简体   繁体   English

如何将事件作为参数传递?

[英]How to pass events as parameters?

I want to have a collection of functions in the class T, defined below. 我想在T类中定义一个函数,定义如下。

function T(){
    this.Funcs = new Array();
    this.appendEvt=function(Obj, Evt, Act){
        switch(Evt){
            case "onclick":
                this.Funcs.push(function(){Obj.onclick=Act;});
                break;
    }       
};

These functions are stored in a array of class T (Funcs). 这些函数存储在T类(Func)的数组中。 This functions must be of the form: 此函数的形式必须为:

Funcs[i]=function(){Obj.Event=FuncWhichContainsActionsWhenTheEventIsTriggered;}

The question is, how can I pass as a parameter any event, like onclick, or "onmouseover,..., so I am able to rewrite the function this.appendEvt like this?: 问题是,如何将任何事件(例如onclick或“ onmouseover ...”)作为参数传递,这样我就可以这样重写函数this.appendEvt?

    this.appendEvt=function(Obj, Evt, Act){
        this.Funcs.push(function(){Obj.Evt=Act;});      
};

您可以只使用“ []”:

Obj[Evt] = Act;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM