繁体   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