我有一个像这样的简单 HTML 表:
<table>
<thead>
<tr>
<th id="lname"><span title="sort this column">Last Name</span>
</th>
<th id="fname"><span title="sort this column">First Name</span>
</th>
<th id="scanned"><span title="sort this column">Scanned In</span>
</th>
<th id="department"><span title="sort this column">Department</span>
</th>
<th id="category"><span title="sort this column">Category</span>
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="blah">LNAME1</td>
<td>FNAME1</td>
<td>06/25/13 12:48 PM</td>
<td>Internal Medicine</td>
<td>Fellow</td>
</tr>
<tr>
<td class="blah">LNAME1</td>
<td>FNAME1</td>
<td>06/25/13 12:48 PM</td>
<td>Internal Medicine</td>
<td>Fellow</td>
</tr>
<tr>
<td class="blah">LNAME1</td>
<td>FNAME1</td>
<td>06/26/13 07:29 AM</td>
<td>Internal Medicine</td>
<td>Faculty</td>
</tr>
<tr>
<td class="blah">LNAME1</td>
<td>FNAME1</td>
<td>06/26/13 07:21 AM</td>
<td>Internal Medicine</td>
<td>Faculty</td>
</tr>
</tbody>
</table>
一个 javascript/jquery 代码是这样的:
var count = 0;
var scannedArr = new Array();
$('table tr').each(function(){
var times = $(this).find('.blah').text();
scannedArr[count] = times;
count++;
});
我在这个 javascript 函数中尝试做的是将scannedArr
数组的元素全部包含在一个 alert() 中。我可以这样做吗?有没有更简单的方法来解决它?
提前致谢!