更新时间:2023-01-19 11:47:01
如果您在全局命名空间中,请使用:
If you're in the global namespace, use this:
window['vid' + num] = 1;
但这是一个非常好的数组用例:
but this is a really good use case for an array:
var numbers = [0, 0, 0]; var num = 1; numbers[num] = 1;
如何在Javascript中使用字符串作为变量名?
使用变量名和字符串组合创建 Javascript 变量
《JavaScript和jQuery实战手册(原书第2版)》——2.6节教程:使用变量创建消息
使用字符串值创建变量名
JavaScript创建对象(四)——组合使用构造函数和原型模式