私は子供のサイズが一貫していないことを発見しました。jquery .children()間違ったサイズを返す
以下は、簡単に参照できるように、アラートでフルコードを添付してください。
データを間違って取得する方法はありますか?
<body>
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" valign="top"><strong>Header Title</strong></td>
</tr>
<tr>
<td height="32" valign="top">Date : <strong>01/01/2010 </strong> <br><div><b></b></div><span></span></td>
</tr>
</table>
</body>
$("td").each(function() {
alert($(this).children().size());
});
//first td showing 1 direct children- <strong>
//second td showing 4 direct children- <strong> <br> <div> <span>
-----
$("tr").each(function() {
alert($(this).children().size());
});
//first tr showing 1 direct children - <td>
//second tr showing 1 direct children - <td>
-----
$("table").each(function() {
alert($(this).children().size());
});
// ERROR
// this table showing 1 direct children only.... something WRONG.
// I thought there are 2 <tr> inside this table?
:
はこれを試してみてください?テーブルの行?ちょうど$( "tr")の長さをしてください。テーブルが多数ある場合は、テーブルにIDを追加して$( "#tableid tr")としてアクセスしてください。 – corroded