我有一块jQuery可以在Chrome中运行良好,但在Firefox或IE中没有。
以下是代码:
//This part works fine
$('#planCompareTable > tbody > tr').each(function() {
var $row = $(this);
if ($row.find('td[data-value="f"]').length == ($row.find('td').length-1)) {
$row.hide();
var rowName = $row.attr('id');
$('input[name="'+$row.attr('id')+'"]').prop('checked',false);
$('input[name="'+$row.attr('id')+'"]').prop('disabled',true);
}
});
//End part that works fine
//Here's the issue lines
if ($('#planCompareTable > tbody > tr:visible').length == 0) {
$('input[name="isNoValues"]').val('true');
}
//End issue lines
这是他正在处理的表格。
<table id="planCompareTable" class="table table-hover table-condensed table-striped" cellspacing="0" cellpadding="10" border="0">
<thead></thead>
<tbody>
<tr style="display:table-row;" id="TestIDHere" data-plan-detail="t" data-plan-compare="t">
<td class="fixedLeftColumn" data-toggle="tooltip" data-hasqtip="0" valign="middle" align="center">
<div class="fieldNameDivIDPart">Deductible (Individual)</div>
</td>
<td id="508352_21772" class="508352_plan commonMaxWidth" valign="middle" align="center">
<div class="commonMaxWidth">$1,500</div>
</td>
<td id="508357_21777" class="508357_plan commonMaxWidth" valign="middle" align="center">
<div class="commonMaxWidth">$500</div>
</td>
<td id="508367_21782" class="508367_plan commonMaxWidth" valign="middle" align="center">
<div class="commonMaxWidth">$750</div>
</td>
</tr>
<tr style="display:table-row;" id="TestID2Here" data-plan-detail="t" data-plan-compare="t">
<td class="fixedLeftColumn" data-toggle="tooltip" data-hasqtip="1" oldtitle="The amount of covered expenses that must be incurred and paid by the insured before benefits become payable by the insurer." title="" valign="middle" align="center">
<div class="fieldNameDivIDPart">Deductible (Family)</div>
</td>
<td id="508352_21772" class="508352_plan commonMaxWidth" valign="middle" align="center">
<div class="commonMaxWidth">$3,000</div>
</td>
<td id="508357_21777" class="508357_plan commonMaxWidth" valign="middle" align="center">
<div class="commonMaxWidth">$1,000</div>
</td>
<td id="508367_21782" class="508367_plan commonMaxWidth" valign="middle" align="center">
<div class="commonMaxWidth">$1,500</div>
</td>
</tr>
</tbody>
</table>
对于if语句,在Chrome上,我会获得准确的长度计数。对于Firefox或IE,我的计数为0,即使会有很多可见的行。
编辑:在DOM中查看更多内容后,如果我在if ($('#planCompareTable > tbody > tr:visible').length == 0) {
行设置断点,则Firefox返回0,Chrome返回9(对于我当前使用的表格而言)。如果我切换Firefox而不是查找tr:hidden
,则会列出所有9行。
我知道Firefox / IE有一些东西让jQuery做了奇怪的事情,但我无法弄清楚在这种情况下它会是什么。有什么建议?在这里,直接的JavaScript会更简单吗?