开发者

Putting a variable into name of function javascript

I want to do the following:

var table = new google.visualization.XXXXX(document.getElementById(divId));

where the X's represent a vari开发者_运维百科able that is set previously.

Just so you know, I'm using Google visualizations here, but I don't think that is necessarily relevant to this question.


Use square bracket notation.

var XXXXX = "someString";
var table = new google.visualization[XXXXX](document.getElementById(divId));


Pretty simple:

var table = new google.visualization[XXXXX](document.getElementById(divId));

Should do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜