【发布时间】:2020-05-11 06:18:05
【问题描述】:
如果产品有缺货消息,我需要显示该产品的库存数量:
<div class="OutOfStockMessage">Sorry, Avocado is not available in the quantity that you selected. Please select a lower quantity to be able to place this order.</div>
<div class="ItemDecription">Avocado<span class="Quantity" style="display:none"> 16 pieces in stock</span></div>
<div class="ItemDecription">Tomato<span class="Quantity" style="display:none"> 97 pieces in stock</span></div>
<div class="ItemDecription">Mushroom<span class="Quantity" style="display:none"> 217 pieces in stock</span></div>
我尝试了这个 jQuery,但它只适用于精确文本匹配,而不适用于部分文本匹配:
if ( $(".OutOfStockMessage").text() == $(".ItemDecription").text() ) {
$(".Quantity").show();
}
这里是小提琴:https://jsfiddle.net/8jmpnwuy/
当 .OutOfStockMessage 包含单词“Avocado”和其他单词时,我需要显示包含单词“Avocado”的 div 内的 span。
【问题讨论】: