javascript 动态定义变量的问题
<script language= "javascript ">
var str = "a,b,c,d ";
var arr=str.split( ", ");
for(i=0;i <=arr.length;i++){
/*
定义语句,达到如下的效果
var a;
var b;
var c;
var d;
*/
这里的语句该怎么写?????
}
</script>
[解决办法]
<script language= "javascript ">
var str = "a,b,c,d ";
var val = " <%=a%> , <%=b%> , <%=c%> , <%=d%> ";
var arr=str.split( ", ");
var valarr=val.split( ", ");
for(i=0;i <=arr.length;i++){
eval( "var "+arr[i]+ "=\ " "+valarr[i]+ "\ "; ");
}
alert(a+ " "+b+ " "+c+ " "+d);
</script>