Call a JavaScript function name using a string?

前端 未结 10 1133
孤独总比滥情好
孤独总比滥情好 2020-11-30 07:07

How can I hook up an event to a function name I have defined as a string?

I\'m using Prototype.js, although this is not Prototype-speficic.

$(inputId         


        
10条回答
  •  猫巷女王i
    2020-11-30 07:38

    If you need to call a string function with arguments, do this:

    window[stringFunctionName].apply( window, arrayOfArguments )
    

    You can use scope in place of window if preferred

提交回复
热议问题