gpt4 book ai didi

jQuery 1.7.1 : length function not working to get table tr count

转载 作者:行者123 更新时间:2023-11-28 04:23:56 25 4
gpt4 key购买 nike

当我们升级到 jQuery 1.7.1 时,这段代码停止工作。 $('table.className > tr').length 返回 0。你能告诉我如何更正它吗?

.NET 代码(执行 jQuery 代码):

public static long GetTableRowCountByCssClass(IWebDriver driver, string cssClass, int exclusionRowCount)
{
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
long count = (long)js.ExecuteScript("return $('table." + cssClass + " > tr').length");
if (count != 0)
{
count = count - exclusionRowCount;
}
return count;
}

HTML代码:

<!-- Products -->
<table class="cart" cellpadding="0" cellspacing="0" border="0">

<thead>
<tr>
<th class="remove">Delete</th>
<th class="prod-desc">Product Description</th>
<th class="ships_w">Ships Within</th>
<th class="price">Unit Price</th>
<th>&nbsp;</th>
<th class="quantity">Qty.</th>
<th class="totals">Total</th>
</tr>
</thead>

<tfoot>
<tr>
<td id="subtotal" class="order_summary_label" colspan="6" >Sub Total: </td>
<td id="subtotal_number" class="order_summary_value">$124.89</td>
</tr>
<tr>
<td id="cart-total-label" class="order_summary_label" colspan="6" >Total: </td>
<td id="cart-total" class="order_summary_value"><strong>$124.89</strong></td>
</tr>
</tfoot>

<tbody>

<tr class="alt">

<td class="remove">
<input class="checkIt" type="checkbox" name="remove[variation][208]" id="remove_208_variation" value="0" />
</td>

<td class="prod-desc">
<div class="imgThmb">
<a href="/product/water-gel" title="Water Gel - Magic Slush Powder - Water Gel 100 gram Jar">
<img src="/img/cache/product/WSPA_500_140_64.jpg" alt="Water Gel - Magic Slush Powder - Water Gel 100 gram Jar" />
</a>
</div>

<a href="/staging/product/water-gel" title="Water Gel - Magic Slush Powder - Water Gel 100 gram Jar" class="clean">
Water Gel - Magic Slush Powder - Water Gel 100 gram Jar
</a>
</td>

<td class="ships_w">
</td>

<td class="price">$6.99</td>

<td class="discount">
</td>

<td class="quantity">
<input type="text" class="quantity_box quantity" name="quantities[variation][208]" id="quantity_variation_208" value="5" maxlength="4" />
</td>

<td class="totals"><strong>$34.95</strong></td>

</tr>

<tr >

<td class="remove">
<input class="checkIt" type="checkbox" name="remove[variation][1118]" id="remove_1118_variation" value="0" />
</td>

<td class="prod-desc">
<div class="imgThmb">
<a href="/product/flying-film-canisters" title="Flying Film Canisters Kit - Flying Film Canisters Activity Kit">
<img src="/img/cache/product/film_canister_launcher_2011011240_64.jpg" alt="Flying Film Canisters Kit - Flying Film Canisters Activity Kit" />
</a>
</div>

<a href="/product/flying-film-canisters" title="Flying Film Canisters Kit - Flying Film Canisters Activity Kit" class="clean">
Flying Film Canisters Kit - Flying Film Canisters Activity Kit
</a>
</td>

<td class="ships_w">
</td>

<td class="price">$14.99</td>

<td class="discount">
</td>

<td class="quantity">
<input type="text" class="quantity_box quantity" name="quantities[variation][1118]" id="quantity_variation_1118" value="6" maxlength="4" />
</td>

<td class="totals"><strong>$89.94</strong></td>

</tr>

</tbody>

</table>

最佳答案

问题是 tr 不是,也不可能是 table 的直接子级元素。它是 tbody 元素的子元素,如果页面作者未将其放置在 table 中,浏览器会自动将其放置在该元素中。

如果你尝试,而不是:$('table.className > tbody > tr').length 它应该工作。

关于jQuery 1.7.1 : length function not working to get table tr count,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9846330/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com