隔行换色的老有关问题
Jun 13, 2016 am 10:46 AM
隔行换色的老问题?
想实现在网页上显示隔行换色的功能,我用的是下面的第二种方法,理论上是可以的啊,结果全是一种颜色,后来查了查,还有第一种方法,挺好用的。只是想知道第二种方法那里出了问题,很困惑,以前都行的,查了好多资料,没有详解,求高手指点……
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> //方法一 while($result=mysql_fetch_array($query)){ $bgcolor=($bgcolor=="blue") ? "white" : "blue"; echo "<tr bgcolor="{$bgcolor}">"; echo "<td><a href="detail.php?gid=%7B%24result%5B'gid'%5D%7D">{$result['gname']}</a></td>"; echo "<td>{$result['endtime']}</td>"; echo "<td>{$result['current_price']}</td>"; echo "<td>{$result['reply_num']}</td>"; echo "</tr>"; } //方法二 $flag=1; while($result=mysql_fetch_array($query)){ if($flag % 2 == 0) $bgcolor="yellow";else $bgbolor="white"; //这种方式理论上可以阿 echo "<tr bgcolor="{$bgcolor}">"; echo "<td><a href="detail.php?gid=%7B%24result%5B'gid'%5D%7D">{$result['gname']}</a></td>"; echo "<td>{$result['endtime']}</td>"; echo "<td>{$result['current_price']}</td>"; echo "<td>{$result['reply_num']}</td>"; echo "</tr>"; $flag++; }
------解决方案--------------------
为毛不用jquery在前端做??代码取余效率是个问题
------解决方案--------------------
if($flag % 2 == 0) $bgcolor="yellow";else $bgbolor="white";
$bgcolor !!!
自己写错了,怪谁呢?
------解决方案--------------------
楼主先输出$flag % 2
echo $flag % 2;echo '
';
看看是不是x0x0x0x0x0的格式。如果是的。在看是不是css样式问题
style="background:颜色"
------解决方案--------------------

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the differences between Huawei GT3 Pro and GT4?

Fix: Snipping tool not working in Windows 11

Five selected Go language open source projects to take you to explore the technology world

Go language development essentials: 5 popular framework recommendations

How to Fix Can't Connect to App Store Error on iPhone

Implementing distributed task scheduling using Golang's web framework Echo framework

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher?
