zoukankan      html  css  js  c++  java
  • 三种php表格隔行换色

    第一种for{}eles{}:

      

         <?php
              echo "<table width='80%' border = 1 cellpadding=5 cellspacing=0>";
              for ($i = 1; $i <= 5; $i++){
              if($i % 2 == 0){
              echo '<tr align="center" bgcolor="red">';
              }else{
              echo '<tr align="center">';
              }

              for ($j = 1; $j<= 8; $j++){

              echo '<td>'.$i * $j.'</td>';

              }
              echo '</tr>';
              }
                echo '</table>';

              ?>

    第二种方法while

              

                <?php
                  echo "<table width='80%' border = 1 cellpadding=5 cellspacing=0>";
                  $l = 1;
                  while ($l <= 5) {
                  if ($l % 2 == 0) {
                  echo '<tr align="center" bgcolor="red">';
                    }else{
                  '<tr align="center">';
                  }

                  $m = 1;
                  while ($m <= 8) {
                    echo '<td>'.$l * $m.'</td>';
                  $m++;
                  }
                  echo '</tr>';
                  $l++;
                  }

                  ?>

    第三种方法do{}while{}

                  <?php      

                  echo "<table width='80%' border = 1 cellpadding=5 cellspacing=0>";
                  $k = 1;
                  do{
                  if($k % 2 == 0){
                  echo '<tr align="center" bgcolor="red">';
                  }else{
                  echo '<tr align="center">';
                  }
                  $n = 1;
                  while ($n <=8) {
                  echo '<td>'.$k * $n .'</td>';
                  $n++;
                  }
                  echo '</tr>';
                  $k++;
                  }while($k <= 5);

                ?>

      

  • 相关阅读:
    linux下查看主板内存槽与内存信息
    centos 6 与 centos 7 服务开机启动、关闭设置的方法
    linux 配置本地光盘YUM源
    linux crontab定时任务不执行
    Linux下安装MySQL5.6
    Linux shell 自动删除n天前日志
    nginx request_time 和upstream_response_time
    linux中文件多行合并为一行的例子
    awk 处理文本:行转列,列转行
    nfs环境搭建报错clnt_create: RPC: Program not registered
  • 原文地址:https://www.cnblogs.com/tiny-bj/p/3812970.html
Copyright © 2011-2022 走看看