【发布时间】:2017-09-08 02:44:23
【问题描述】:
如果我想仅在标题中出现“Apple iPad”字样时显示 install_option 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');
}
});
【问题讨论】:
-
上面显示的 jsfiddle 不起作用。这个可以:jsfiddle.net/54eg8cn6
-
你可以使用
.indexOf,比如this
标签: javascript jquery css contains