【发布时间】:2014-10-01 11:45:19
【问题描述】:
目标:
- 在 javascript/jquery 中创建二维数组
- 将数据推入其中
- 循环遍历每个键值对
- 循环调用函数
代码:
var IDs = [];
/* Find Input elements and push its ID & Value into an array */
$('#divDynamicFields').find("input").each(function () {
IDs.push(this.id, $(this).val());
});
console.log(IDs); /* Now it prints string seprated by ',' */
/* Loop Through Each element in 2D array */
$.each(IDs, function(key, value) {
$.each(key, function(innerKey, innerValue){
CallFunction(id,val);
/* Will This Work ? */
}
}
【问题讨论】:
-
我在那个一维数组中看不到二维。所以我想答案是否定的,那是行不通的。
-
@Spokey 我想创建将
id,value保存为对的二维数组 -
看看fiddle。
-
@Regent 将其发布为答案 :)
-
@Shaggy 好的,因为它看起来很适合你 :)
标签: javascript jquery arrays