jquery에 대한 멍청한 반응입니다. 붙어서 도움을 청할 것이다. 현재 특정 페이지에서 데이터를 가져 오는 도구를 작성 중입니다. 페이지는 다음과 같습니다 : 나는 아이디 parent0 및 child0와 단지 <tr>
블록에서 모든 데이터를 수집하기 위해 노력하고있어jquery는 id를 기반으로 한 요소를 일치시킵니다.
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()
]
:
다음<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와의 조각입니다.
현재 도구는 두 테이블의 모든 데이터를 텍스트로 캡처합니다. 이상적으로는 모든 <TR>
블록을 개별적으로 캡처 할 수 있도록 배열에 넣을 수있게하고 싶습니다.
의 ID 값은 고유해야합니다, 당신은 현재 여러 요소에 동일한 ID를 할당하고 있습니다 : 사실,이 솔루션은 더 우아한라고 생각합니다. – Paul
ID를 두 번 이상 사용하지 마십시오. http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 –