- 通过每个键在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 ? */
}
}
我在这个1维数组中看不到2个维度。所以我想答案是不可行的,那是行不通的。 – Spokey 2014-10-01 11:50:48
@Spokey我想创建2d数组,其中包含'id,value'对 – Shaggy 2014-10-01 11:52:25
看看[fiddle](http://jsfiddle.net/2wyoe27w/)。 – Regent 2014-10-01 11:56:42