【发布时间】:2015-08-10 13:12:33
【问题描述】:
我正在尝试更改缺货产品的文字。这是我目前所拥有的:
$( ".box.stock:contains('0 Stock')" ).text('Temporarily out of stock. Call to order. ').addClass( "Lager" );
这有效,但它也适用于其中包含零的所有产品。如何将其更改为仅带有“0”的库存状态?
【问题讨论】:
标签: javascript jquery
我正在尝试更改缺货产品的文字。这是我目前所拥有的:
$( ".box.stock:contains('0 Stock')" ).text('Temporarily out of stock. Call to order. ').addClass( "Lager" );
这有效,但它也适用于其中包含零的所有产品。如何将其更改为仅带有“0”的库存状态?
【问题讨论】:
标签: javascript jquery
你不能用 contains 做到这一点。您需要使用过滤器
$(".box.stock").filter( function() {
return $(this).text() === "0 Stock";
}).text('Temporarily out of stock. Call to order. ').addClass( "Lager" )
【讨论】: