小编Gui*_*sos的帖子

JS中如何使用动态名称调用函数

我试图按照我在下面发布的相同示例将其称为函数。所以问题是我用来调用函数的方法不起作用...我需要类似的东西,因为我将通过监听事件来调用这些函数。有人知道立即采取行动吗?

谢谢。

//variables
var ta = 3213;
var da = 44;
var s = [];

//Create string representation of function
s[1] = "function test0(){  alert(" + da + "); }";
s[0] = "function test1(){  alert(" + ta +"); }";

//"Register" the function
for(i=0; i< s.length; i++){
	eval(s[i]);
}

// calling the function
this["test"+1];
Run Code Online (Sandbox Code Playgroud)

javascript canvas

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

canvas ×1

javascript ×1