最简单的方式来替换行的颜色 PHP/HTML?
这是我的例子 PHP. 任何人都可以找到较短的/简单的方法要做吗?
其他语言的示例也很有意思。
foreach/$posts as $post/{?
<div class="<?=/$c++%2==1/?‘odd’:NULL?>">
<?=$post?>
</div>
}?
<style>
.odd{background-color:red;}
</style>
其他语言的示例也很有意思。
没有找到相关结果
已邀请:
19 个回复
快网
赞同来自:
[code]$c = true; // Let's not forget to initialize our variables, shall we?
foreach/$posts as $post/
echo '<div'. $c="!$c/?'" ':''="" ."="" class="odd">$post</div'.>
郭文康
赞同来自:
使用 jQuery, 这很简单:
帅驴
赞同来自:
但如果您真的希望您的用户看到这种颜色,最好不要使用它。
八刀丁二
赞同来自:
也 Django:
君笑尘
赞同来自:
冰洋
赞同来自:
然后用它 /使用你的例子/:
二哥
赞同来自:
<div<?php $alt="" '="" '';="" :="" ?="" class="odd" echo="">>
<!-- Content -->
</div<?php>
诸葛浮云
赞同来自:
假设您可以使用选择器 CSS3, 你可以做一些这样的事情
即使是支持 CSS2 和 mootools /图书馆 javascript/ 您可以通过此替换风格。 javascript
如果你什么都没有 php a it, 您可以使用数组轻微简化代码。
龙天
赞同来自:
裸奔
赞同来自:
如何使用:
</tr></tr>
石油百科
赞同来自:
龙天
赞同来自:
http://docs.jquery.com/Selectors/odd
和
http://docs.jquery.com/Selectors/even
, 然后可以连接到添加某些
http://docs.jquery.com/CSS/css#namevalue
或连接K. CSS 更普遍,
http://docs.jquery.com/Attributes/addClass#class
.
龙天
赞同来自:
a
和
b
, 在循环中做的好方法是:
您也可以在没有添加和减法的情况下执行此操作:
在哪里
^
- 手术 XOR.
如果你只是想交替 0 和 1, 你能行的:
当然你可以使用
x
作为颜色的索引,风格的课程 CSS 等等。
三叔
赞同来自:
</div>
<div class="answer_text">
您可以滥用该地区 $GLOBAL 要存储当前所选的类状态,请参阅下面的函数 table_row_toggle//. 是的,我知道它肮脏的虐待 $GLOBAL 行动领域,但嘿,我们在这里为了纠正问题,对吗? :/
调用表线函数 HTML:
功能B. PHP:
</tr></div>
<div class="answer_text">
发现 Vilx, 但总是为了速度而微钱 /页面重量/
</tr></div>
<div class="answer_text">
一个简单的小功能,适合我。
</div>
<div class="answer_text">
用这样的东西:
</div>
<div class="answer_text">
在 PHP 我使用这个代码:
来源:
http://sklueh.de/2013/11/einfa ... -php/
/
</div>
</div>
卫东
赞同来自:
调用表线函数 HTML:
功能B. PHP:
</tr>
八刀丁二
赞同来自:
</tr>
詹大官人
赞同来自:
卫东
赞同来自:
</div
<div class="answer_text">
在 PHP 我使用这个代码:
来源:
http://sklueh.de/2013/11/einfa ... -php/
/
</div>
董宝中
赞同来自:
来源:
http://sklueh.de/2013/11/einfa ... -php/
/