簡體   English   中英

html屬性之間的條件語句(php)?

[英]Conditional Statements(php) between html attributes?

我正在重構PHP網頁,並且需要動態插入一個類。

根據項目的結構,一個解決方案是使用三元運算符<?($selectedElement=="KeyOne"? 'linkactive': 'normalLink') ?>處理之前分配的變量的值:

<a id="customid_generatebytool" class="<?($selectedElement=="KeyOne"? 'linkactive': 'normalLink') ?>" href="anotherPage.php" ...>
....
</a>

<a id="customid_generatebytool" class="<?($selectedElement=="KeyTwo"? 'linkactive': 'normalLink') ?>" href="Page2.php" ...>
....
</a>

但是我上面的代碼不起作用,我是php新手。

提前致謝。

添加echo

<a id="customid_generatebytool" class="<?php echo ($selectedElement=="KeyOne"? 'linkactive': 'normalLink') ?>" href="anotherPage.php" ...>

您已使用php短標簽<? 確保在您的php.ini中啟用了它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM