我想做一个3列,并将last类添加到第三列。我试过这段代码:
<?php for ($i = 0; $i < 9; $i = $i + 4) { //can't touch this line ?>
<?php for ($j = $i; $j < ($i + 4); $j++) { //can't touch this line ?>
<?php $counter=0; ?>
<div class="span-5<?php if ($counter % 3 == 0) { echo " last"; } ?>">
Info
</div>
<?php } ?>
<?php } ?>但这并不管用。(它将last类分配给第二列)
发布于 2010-12-13 19:15:44
在合适的时间添加一个$counter++,它就会正常工作。
<?php for ($i = 0; $i < 9; $i = $i + 4) { //can't touch this line ?>
<?php for ($j = $i; $j < ($i + 4); $j++) { //can't touch this line ?>
<?php $counter=0; ?>
<div class="span-5<?php $counter++; if ($counter % 3 == 0) { echo " last"; } ?>">
Info
</div>
<?php } ?>
<?php } ?>发布于 2010-12-13 19:10:12
尝试this.it可能会对您有所帮助。
<?php for ($i = 0; $i < 9; $i = $i + 4) { //can't touch this line ?>
<?php for ($j = $i; $j < ($i + 4); $j++) { //can't touch this line ?>
<?php if($j == 3){
$class = 'class="last"';
}else{
$class = '';
} ?>
<div <?php $class; ?>>
Info
</div>
<?php } ?>
<?php } ?>谢谢。
发布于 2010-12-13 19:12:00
或者只是将您的$counter设置为$j+1。
https://stackoverflow.com/questions/4428125
复制相似问题