Mil*_*ilo 6 html javascript jquery asp.net-mvc-3
我有一张桌子:
<table id="ItemsTable" >?
<tbody>
<tr>
<th>
Number
</th>
<th>
Number2
</th>
</tr>
<tr>
<td>32174711</td> <td>32174714</td>
</tr>
<tr>
<td>32174712</td> <td>32174713</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我需要将值32174711和32174712以及列号的每个其他值放入数组或列表中,我使用的是jquery 1.8.2.
Dyl*_*SUN 13
var arr = [];
$("#ItemsTable tr").each(function(){
arr.push($(this).find("td:first").text()); //put elements into array
});
Run Code Online (Sandbox Code Playgroud)
请参阅此链接以获取演示:
你可以使用map方法:
var arr = $('#ItemsTable tr').find('td:first').map(function(){
return $(this).text()
}).get()
Run Code Online (Sandbox Code Playgroud)
从jQuery map()文档:
描述:通过函数传递当前匹配集中的每个元素,生成一个包含返回值的新jQuery对象..由于返回值是一个jQuery包装的数组,因此get()返回的对象与基本数组一起使用是很常见的.
| 归档时间: |
|
| 查看次数: |
24386 次 |
| 最近记录: |