我想检查变量是否包含*或**,然后我希望它根据找到的内容显示div。我写了一个不起作用的剧本。
我现在已将其更改为使用PHP并且它现在正在运行:
<?php
if (strpos($this->element->product_description, '*') !== false) {
echo '<div class="asterisk">
<ul class="asterix">
<li>* Subject to receipt of payment and print ready artwork or sign off of proofs. Large quantities may require a longer lead time.</li>
<li>** Custom sizes can be manufactured to order, longer lead times may apply.</li>
</ul>
</div>';
};
?>
答案 0 :(得分:1)
试试这个。使用javascript
选择器
jQuery
indexOf方法
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<div class="asterisk" style="display: none;">
<ul class="asterix">
<li>* Subject to receipt of payment and print ready artwork or sign off of proofs. Large quantities may require a longer lead time.</li>
<li>** Custom sizes can be manufactured to order, longer lead times may apply.</li>
</ul>
</div>
<script>
if ($(".asterisk ul li").text().indexOf('*') > -1) {
$('.asterisk').css('display', 'block');
}
</script>
</body>
</html>
&#13;