use*_*510 0 arrays each jquery loops
我使用以下行来创建与特定搜索词匹配的所有TD的数组.如果TD包含我的搜索词,则highlight添加了" " 类.
到目前为止,下面的工作正常我唯一的问题是,如果一列不包含我的搜索词,我需要添加0(一列有或没有值,但它不能在同一列中出现多次).
有问题的列是列,2, 4, 6, 8, 10, 12因此我的数组应始终包含6个值,如果其中一列不包含搜索项,则只显示0.
换句话说:我需要检查列是否包含具有"突出显示"类的TD.
我的功能:
var arr = new Array();
$('.highlight').each(function() {
arr.push($(this).text());
});
Run Code Online (Sandbox Code Playgroud)
示例HTML:
<table id="myTable">
<thead>
<tr>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td class="mayContainSearchTerm highlight">search term</td>
<td>5</td>
<td class="mayContainSearchTerm highlight">search term</td>
<td>7</td>
<td class="mayContainSearchTerm highlight">search term</td>
<td>3</td>
<td class="mayContainSearchTerm">other data</td>
<td>1</td>
<td class="mayContainSearchTerm highlight">search term</td>
<td>5</td>
<td class="mayContainSearchTerm">other data</td>
<td>1</td>
</tr>
// more TRs...
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
希望有人可以帮助我.蒂姆,非常感谢.
如果我明白你的意思,你在页面中没有任何其他TD(如果你需要确定你想要的那些选择)
你可以用这个编辑你的鳕鱼:
var arr = new Array();
$('TD').each(function() {
if( $(this).hasClass("highlight") )
arr.push($(this).text());
else
arr.push("0");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9541 次 |
| 最近记录: |