jqueryのnoobです。立ち往生して助けていただければ幸いです。 現在、特定のページからデータを取得するツールを構築しています。ページには、次のようになります。以下はjqueryはidに基づいて要素を一致させます
<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()
]
私はIDの親0、およびchild0でちょうど<tr>
ブロックからすべてのデータをキャプチャしようとしています。
ツールは、現在の動作状態では、2つのテーブル内のすべてのデータをテキストとしてキャプチャします。理想的には、すべての<TR>
ブロックを別々にキャプチャし、それを配列に入れて反復処理できるようにしたいと考えています。
ID値が一意である必要があり、あなたは現在、複数の要素に同じIDを割り当てています。 – Paul
複数のIDを複数回使用しないでください:http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 –