2017-02-17 111 views
-4

我想检查一个变量是否包含*或**,然后我希望它根据找到的内容显示div。我写了一个不起作用的脚本。如果变量包含文本,则显示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

试试这一个。 javascriptindexOfjQuery选择

<!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>

+0

谢谢!不知道为什么我的问题有倒票! – RustyIngles

+0

@RustyIngles你正在写html脚本标签内的php方法。这是问题 – Nitheesh

+0

@RustyIngles如果这是您的预期结果,请批准我的答案。 – Nitheesh

相关问题