我正在开发一家咖啡店产品网站。我们有一个区域,每个产品都有一个咖啡强度指示器。数据库根据强度是强,中,弱还是不适用来生成一个值。不适用于非咖啡产品。如果显示n/a值,隐藏DIV
如果显示n/a,我想隐藏包含div。
我到目前为止的代码如下。我有一些JavaScript代替了数据库显示的文本和强度指标的图片。
如果span标签中的咖啡强度不是我想隐藏的。
这可能吗?
在此先感谢。
<div class="coffee-strength">
<p>Coffee Strength: <span><?php echo $_product->getAttributeText('coffeestrength'); ?></span></p>
</div>
<script type="text/javascript">
jQuery(function ($) {
$('.coffee-strength p span').each(function() {
var string = $.trim($(this).text());
$(this).html('<img src="/images/' + string + '.png" alt="' + string + '" />');
});
});
</script>
也许你可以添加这个'<?PHP的echo $ _product-> getAttributeText( 'coffeestrength');在div的类中,就像JS中的那样,你可以检查这个类来隐藏它。 – Franck