2017-02-17 28 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

相關問題