【发布时间】:2020-05-08 02:31:35
【问题描述】:
我有一个 ~26 td 的表,它们都是复选框,每个复选框都有一个定义的值。行数可能是无限的。
以下是其中一个 td 的示例:
<td style="text-align:center"><input type="checkbox" class="largerCheckbox" id="Missing Date" value="true"'+ZMISSDATE+'></td>
我想在 JQuery 中创建一个数组,该数组将显示每一行的值。我完成了数组,但是当我在控制台记录它时,每行的所有 td 都是空白的。
这是我创建数组的 JQuery:
var mainArray = [];
$("table#dt-multi-checkbox tr ").each(function(){ /* Loop through all rows of the table(id='dt-multi-checkbox') */
var tempArray = []; /* Declare a temporary array */
$(this).find('td').each(function(){ /* Loop through all elements inside a row */
tempArray.push($(this).val()); /* Use array push() function to add an element to the array */
});
mainArray.push(tempArray);
});
console.log(mainArray);
谁能告诉我哪里出错了?为什么值 ="true 没有显示在我的数组中(来自我上面提到的示例 td),我怎样才能让它显示数组中的值? 以下是我在控制台记录它时的样子:
Array(26)
0: ""
1: ""
2: ""
3: ""
4: ""
5: ""
6: ""
7: ""
8: ""
9: ""
10: ""
11: ""
12: ""
13: ""
14: ""
15: ""
16: ""
17: ""
18: ""
19: ""
20: ""
21: ""
22: ""
23: ""
24: ""
25: ""
谢谢你,我很感激你能指导我的任何方向。
【问题讨论】:
标签: javascript html jquery arrays