使用字符串调用JavaScript函数名称? [英] Call a JavaScript function name using a string?
本文介绍了使用字符串调用JavaScript函数名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将事件连接到我已定义为字符串的函数名?
How can I hook up an event to a function name I have defined as a string?
我正在使用Prototype.js,尽管这不是Prototype- speficic。
I'm using Prototype.js, although this is not Prototype-speficic.
$(inputId).observe('click', formData.fields[x].onclick);
这会导致JavaScript抱怨我的处理程序不是函数。我不希望我们使用 eval()
。
This would result in JavaScript complaining that my handler is not a function. I would prefer not us use eval()
.
推荐答案
如果函数在全局范围内,您可以使用window对象获取它:
If the function is in the global scope, you can get it using the window object:
var myFunc = window[myFuncName];
这篇关于使用字符串调用JavaScript函数名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文