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