Call javascript function which name is in variable [duplicate]

自作多情 提交于 2019-11-30 07:09:37

问题


The problem is next: Assume that we have a select. Onchange event we need to call some function, but name of this function kept in variable. How to call this function ?


回答1:


window[name]()

You can call functions by name reference by selecting them as a property of window and executing them




回答2:


have you tried variableName(); ?

We often pass around callback functions, which might look something like this

function doSomething(callbackFunction){
    // some happy code
    callbackFunction()
}


来源:https://stackoverflow.com/questions/6871165/call-javascript-function-which-name-is-in-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!