我是 jquery 的菜鸟。卡住了,希望能得到一些帮助。目前正在构建一个从特定页面获取数据的工具。页面如下所示:
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
<tbody> //This is data group 1
<tr id="parent0"> //Record 1
<td align="left"> <---------- text1 here -------> </td>
<td align="left"> <---------- text2 here -------> </td>
<td align="left"> <---------- text3 here -------> </td>
</tr>
<tr id="parent0"> //Record 2
<td align="left"> <---------- text1 here -------> </td>
<td align="left"> <---------- text2 here -------> </td>
<td align="left"> <---------- text3 here -------> </td>
</tr>
</tbody>
</table>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
<tbody> //This is data group 2
<tr id="child0"> //Record 1
<td align="left"> <---------- text1 here -------> </td>
<td align="left"> <---------- text2 here -------> </td>
<td align="left"> <---------- text3 here -------> </td>
</tr>
<tr id="child0"> //Record 2
<td align="left"> <---------- text1 here -------> </td>
<td align="left"> <---------- text2 here -------> </td>
<td align="left"> <---------- text3 here -------> </td>
</tr>
</tbody>
</table>
下面是jquery的一个片段:
ancestor = $(this).closest("tr[id]");
matchedElement = $(this).first();
originalBgColor = $(matchedElement).css('background-color');
$(matchedElement).css('background-color', 'green');
$(matchedElement).bind('click.annotator', function(event) {
event.stopPropagation();
event.preventDefault();
self.port.emit('show',
[
document.location.toString(),
$(ancestor).attr("child0"),
$(matchedElement).text()
]
我正在尝试仅从<tr>
ID 为 parent0 和 child0 的块中捕获所有数据。
在其当前工作状态下,该工具将两个表中的所有数据作为文本捕获。理想情况下,我希望能够分别捕获所有<TR>
块,将它们放在一个数组中,然后我可以对其进行迭代。