这是一个简单的问题,快速代码转储。我有
$insides = $('<thead><tr><th><!--Blank space --></th></tr></thead><tbody><tr class="green-row"><td>Opportunities to Date</td></tr><tr><td>Number of wins</td></tr><tr><td>Number of active deals</td></tr><tr><td>Number of persmission to pursue</td></tr><tr><td>Number of persmission to contact</td></tr><tr><td>Number of deals lost</td></tr><tr><td>Number of deals disqualified</td></tr><tr><td id="deal%-0365">% deals with ...<input class="filterer" type="checkbox" checked="true"/></td></tr><tr><td id="deal%-VM">% deals with ...<input class="filterer" type="checkbox" checked="true"/></td></tr><tr><td id="deal%-AM">% deals with ...<input class="filterer" type="checkbox" checked="true"/></td></tr><tr><td>Current total pipeline value</td></tr></tbody></table>');
for ( var region in this.DealsByRegion )
{
$insides.find('thead > tr').append('<th class="region" id="region-' + region + '">' + region + '<input class="filterer" type="checkbox" checked="true"</input>');
}
并且它无效,因为
$insides.find('thead > tr')
没有返回任何内容(即$insides.find('thead > tr').length = 0
)。为什么? <tr><th><!--Blank space --></th></tr>
的{{1}}的孩子不是thead
的后代吗?
答案 0 :(得分:6)
那是因为$insides
变量中的当前根元素已经是thead
节点。所以下面的代码:
$insides.find('thead > tr')
转换为css选择器
thead thead > tr
更合适的选择器是:
$insides.filter('thead').children('tr')