我在Javascripts中有几个数组,例如
a_array [0] ="abc";
b_array [0] ="bcd";
c_array [0] ="cde";
我有一个获取数组名称的函数.
function perform(array_name){
array_name = eval(array_name);
alert(array_name[0]);
}
perform("a_array");
perform("b_array");
perform("c_array");
Run Code Online (Sandbox Code Playgroud)
目前,我使用eval()来做我想要的.
有没有方法不在这里使用eval()?
我有一个js功能
我想为变量赋一个变量
我的变量是在forloop中
我有两个变量
即;
var spcd_1= "http://www.colbridge.com";
var spcd_2 = "http://www.google.com";
Run Code Online (Sandbox Code Playgroud)
下面是我的js功能
function openNewWindow(spcd) {
//alert("hello");
var tt = spcd;
alert(tt);
var i=0;
var spcd_1= "http://www.colbridge.com";
var spcd_2 = "http://www.google.com";
for(i=1;i<3;i++)
{
var theurl="'spcd_'+i";
popupWin = window.open(theurl,
'_blank',
'menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=640, height=480, left=0, top=0')
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题在这里
var theurl=spcd_+i;
Run Code Online (Sandbox Code Playgroud)
我想改变theurl价值spcd_1和spcd_2
如何在for循环中正确分配
var theurl=spcd_+i;
Run Code Online (Sandbox Code Playgroud)
谁能告诉我正确的方法.
谢谢
我有以下变量:
var MyVar = "8";
Run Code Online (Sandbox Code Playgroud)
我有两个字符串例如:
var foo = "My";
var bar = "Var";
Run Code Online (Sandbox Code Playgroud)
现在我想提醒MyVar值,意思是警告"8"而不是"MyVar"
alert(foo + bar) // returns "MyVar"
Run Code Online (Sandbox Code Playgroud) 如何在没有eval的情况下在运行时组装Javascript中的var?
var lc = $('.bezeichnung-1').length;
for (var lt = 1; lt <= lc; lt++) {
eval("var neuerwert"+lt+"=0;"); // this works but I don't want to use it because I read that eval is bad
}
var lc = $('.bezeichnung-1').length;
for (var lt = 1; lt <= lc; lt++) {
window["var neuerwert"+lt] = 0; // this does not work
}
Run Code Online (Sandbox Code Playgroud)