我有几个链接,我想追加单词"销售"的基础上找到链接的字符串,我已经成功地使用了下面的代码.但是,如果可能的话,我希望能够让代码查看多个字符串.
目前,"销售"一词被附加到包含字符串"衬衫"的链接上.我也希望它适用于所有的链接,包含"夹克"以及.
有没有办法以数组的形式完成这项工作?
<div>
<div class="link"><a href="/products/WHITESHIRT">White Shirt</a></div>
<div class="link"><a href="/products/BLACKSHIRT">Black Shirt</a></div>
<div class="link"><a href="/products/GREENSHIRT">Green Shirt</a></div>
<div class="link"><a href="/products/WHITESHORTS">White Shorts</a></div>
<div class="link"><a href="/products/BLACKTROUSERS">Black Trousers</a></div>
<div class="link"><a href="/products/YELLOWJACKET">Yellow Jacket</a></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(".link a").each(function () {
var href=$(this).prop('href');
if (href.indexOf('SHIRT') > -1) {
$(this).append(" SALE");
}
});
</script>