【问题标题】:Update HTML container text on text match using jQuery使用 jQuery 在文本匹配上更新 HTML 容器文本
【发布时间】:2015-08-10 13:12:33
【问题描述】:

我正在尝试更改缺货产品的文字。这是我目前所拥有的:

$( ".box.stock:contains('0 Stock')" ).text('Temporarily out of stock. Call to order. ').addClass( "Lager" );

这有效,但它也适用于其中包含零的所有产品。如何将其更改为仅带有“0”的库存状态?

【问题讨论】:

标签: javascript jquery


【解决方案1】:

你不能用 contains 做到这一点。您需要使用过滤器

$(".box.stock").filter( function() {  
    return $(this).text() === "0 Stock";
}).text('Temporarily out of stock. Call to order. ').addClass( "Lager" )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-07
    • 2017-11-21
    • 2013-12-06
    • 2016-12-13
    • 1970-01-01
    • 2018-01-05
    • 2021-12-11
    相关资源
    最近更新 更多