如果我想显示install_option div 只有如果单词“Apple iPad”出现在标题中?jQuery - 如果它只匹配两个特定单词,则显示div
也可以做匹配,如果一个产品叫iPad的(小写)或iPad
<h1 id="pbtitle">Apple iPad 3</h1>
<div class="install_option" style="display:none;">
<div style="width:35%; box-sizing:border-box; float:left;">
<h3 style="font-weight:bold;">Would you like to view accessories?</h3>
</div>
<div class="apple_install_option" style="padding-top:20px;">
<a href="https://www.apple.com" target="_blank">
<img alt="Apple.com" src="http://cdn.cultofmac.com/wp-content/uploads/2012/10/lightningconnector.jpg" style="margin-right:20px; max-width:200px; height: auto;">
</a>
</div>
</div>
$(".install_option").each(function() {
var brand = $("h1#pbtitle").text().toLowerCase();
if (brand != "Lenovo") {
$('.install_option').css('display', 'block');
}
});
https://jsfiddle.net/ote8w56v/
上面显示的的jsfiddle不起作用。这个可以:https://jsfiddle.net/54eg8cn6/ – Syno
你可以使用'.indexOf',就像[this](https://jsfiddle.net/ote8w56v/3/) – George