本文介绍了是否可以创建动态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 例如, 函数addNew(i){ var''element''& i ... } 如果可能,怎么样? 谢谢。For instance,function addNew(i) {var ''element''&i...}If possible, how to?Thanks.推荐答案你可以使用eval函数.... var somVar =" SomeValue" ;; var Elementname =" var yourName" + somVar +" ='''Hello'';" ;; eval(Elementname); alert(yourNameSomeValue); GrahamYou can use the eval function....var somVar ="SomeValue";var Elementname = "var yourName" + somVar + "=''Hello'';";eval(Elementname);alert(yourNameSomeValue);Graham DL写道:DL wrote: 例如, 函数addNew(i){ var''元素''& i .. } 如果可能,怎么样?For instance,function addNew(i) {var ''element''&i..}If possible, how to? 虽然eval()是可能的,而且可能是坏的,很可能 是你真的不需要什么你要。考虑一下: 函数addNew(i) { var a = []; a [i] = 42; ... } PointedEars - 任何拍下这个页面的人最好用浏览器X查看标签 a网页似乎渴望过去的糟糕时光,在网络之前, 当你很少有机会阅读另一台计算机,另一台文字处理器或其他网络上的文件时。 - Tim Berners-LeeWhile eval() is a possibility, and a bad one at that, chancesare that you really don''t need what you want. Consider this:function addNew(i){var a = [];a[i] = 42;...}PointedEars--Anyone who slaps a ''this page is best viewed with Browser X'' label ona Web page appears to be yearning for the bad old days, before the Web,when you had very little chance of reading a document written on anothercomputer, another word processor, or another network. -- Tim Berners-Lee 5月10日下午3:34 *,Thomas''PointedEars''Lahn< PointedE ... @ web.de> 写道:On May 10, 3:34*pm, Thomas ''PointedEars'' Lahn <[email protected]>wrote: DL写道:DL wrote: 例如, For instance, function addNew(i){ var''element''& i .. } function addNew(i) { var ''element''&i .. } 如果可能,该如何? If possible, how to? 虽然eval()是可能的,而且可能是坏的,机会 是你真的不需要什么你要。 *考虑一下: *函数addNew(i) * { * * var a = []; * * a [i] = 42; * * ... *} PointedEars - 任何拍下这个页面的人最好用浏览器X查看标签 a网页似乎是渴望过去的糟糕时光,在网络之前,当你几乎没有机会阅读另一台计算机,另一台文字处理器或其他网络上写的文件的时候,这就是b $ b。 - Tim Berners-LeeWhile eval() is a possibility, and a bad one at that, chancesare that you really don''t need what you want. *Consider this:* function addNew(i)* {* * var a = [];* * a[i] = 42;* * ...* }PointedEars--Anyone who slaps a ''this page is best viewed with Browser X'' label ona Web page appears to be yearning for the bad old days, before the Web,when you had very little chance of reading a document written on anothercomputer, another word processor, or another network. -- Tim Berners-Lee 有哪些替代方案?What alternatives are there? 这篇关于是否可以创建动态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-22 12:34