本文介绍了备用表行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我很高兴地说,在你的帮助下,我在Ajax上的表现一直很好。谢谢你帮我开始。我现在有一个小问题。我从数据库中提取记录并在表中传递查询结果。我想要一些帮助代码为备用行着色。 [PHP] 函数printQuery($ param) { echo"< table width = 100%valign = center>" ;; echo"< tr>" ;; foreach($ param as $ key => $ result) echo"< td>" ;; if(is_array($ result) ) { printQuery($ result); } else { echo($ result)。 ''< br />''; } echo"< / td>" ;; } } echo"< / td>" ;; echo"< / tr>" ;; echo"< / table>" ;; [/ PHP] 我试过很多CSS和Javascript函数交替着色表行但它们似乎不起作用。没有错误,但不会做替代着色。我也检查了这个论坛,发现下面的代码很有用,但它从CSS中获取color2 CSS的颜色代码,而不是第一行。 http://www.thescripts.com/forum/thre...ate+color .html [PHP] <?php #打印表的开头。 echo" \ n< table>" ;; #循环通过而$ i小于10 #每次将$ i递增一个。 for($ i = 0; $ i< 10; $ i ++) { # $ i%2将数字$ i除以2并返回其余的(0或1) #然后我添加一个,所以这将是1或2 $ color =" color"。 ($ i%2 + 1); #在表格中打印一行。 echo" \ n\t< tr>< ; td class = \" $ color \"> Row $ i< / td>< / tr>" ;; } #打印表的末尾。 echo" \ n< / table>" ;; ?> [/ PHP] 我在代码中更改了以下内容:Hi,I am happy to say that with your help, I have been performing good in Ajax. Thanks for helping me to start with. I have a small problem now. I am pulling records from database and passing result of the query in a table. I would like some help with the code to colour the alternate rows please.[PHP]function printQuery($param) { echo "<table width=100% valign=center>"; echo "<tr>"; foreach ($param as $key => $result) echo "<td>"; if (is_array($result)){printQuery($result);}else{echo ($result) . ''<br />'';}echo "</td>";}} echo "</td>";echo "</tr>";echo "</table>";[/PHP]I tried many CSS and Javascript functions to colour table rows alternatively but they don''t seem to work. No errors but wont do alternate colouring. I checked this forum also and found the following code useful but it takes the colour code from CSS for color2 CSS in every row not the first one. http://www.thescripts.com/forum/thre...ate+color.html[PHP]<?php# Print the start of the table.echo "\n<table>";# Loop throught while $i is less than 10# each time incrementing $i by one.for($i = 0; $i < 10; $i++){ # $i % 2 divides the number $i by 2 and returns the rest (0 or 1) # which I then add one to, so this will alwasy be either 1 or 2 $color = "color". ($i % 2 + 1); # Print a row into the table. echo "\n\t<tr><td class=\"$color\">Row $i</td></tr>";}# Print the end of the table.echo "\n</table>";?>[/PHP]What I changed in my code was the following: 展开 | 选择 | 换行 | 行号推荐答案 param) { echo"< table width = 100 %valign = center>" ;; echo"< tr>" ;; foreach(param) { echo "<table width=100% valign=center>"; echo "<tr>"; foreach ( param as key =>key => 这篇关于备用表行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-03 23:53