【发布时间】:2014-08-03 13:40:24
【问题描述】:
我在用 jQuery 中的另一个变量创建变量时遇到了一些困难。我不知道如何写等式的 var 侧。这是我正在尝试创建的内容:
var $counter= 0;
$('.selector').each(function(){
$counter += 1;
var newVariable-($counter) // this is where I'd like to create the new
// variable with the number from $counter at the end.
});
以创造为目标:
newVariable-1
newVariable-2
newVariable-3...
等等……
【问题讨论】:
-
可读性提示:尝试使用以
$开头的变量,仅用于缓存 jQuery 选择。 (var $counter = $('#counter'); var counter = 0;)
标签: javascript jquery variables dynamic each