0
當前匹配的關鍵字然後執行操作。如何將排除列表納入下面的功能?在jQuery中爲indexOf關鍵字匹配添加關鍵字排除
<!-- Product names include Apple iPad, Acer Iconia, Lenovo Thinkpad plus Generic, No Brand-->
<h1 id="pbtitle">Apple iPad 3</h1>
<div class="install_option" style="display:none;">
<div style="box-sizing:border-box; float:left;">
<a href="https://www.example.com/acc" target="_blank">
<h3 style="font-weight:bold;">Would you like to view accessories?</h3>
</a>
</div>
</div>
var options = ['Acer','Apple','Lenovo'];
var exclusions = ['Generic','No Brand'];
var text = $("#pbtitle").text();
options.forEach(function(element) {
if (text.indexOf(element) != -1) { // if its NOT -1 (-1 = not found)
$('.install_option').css('display','block'); // then we found it .. do your magic
}
});
排除應該是'== -1' –
隱而不宣」還沒有工作。排除是否需要添加到forEach? – me9867
options.forEach && exclusions.forEach? – me9867