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);

                ?>

      

  • 相关阅读:
    如何将windows版的vim界面语言(默认为中文)设置成英文(转)
    hdu 1023 Train Problem II 完整高精度模板(以输出大Catalan为例)
    第三届蓝桥杯预赛真题解答
    hdu 1016 Prime Ring Problem (dfs)
    博客搬家
    void main()是错的!
    c,c++产生随机数详解
    高性能网站的十四条黄金法则
    云端
    jQuery Tools:Web开发必备的 jQuery UI 库
  • 原文地址:https://www.cnblogs.com/tiny-bj/p/3812970.html
Copyright © 2011-2022 走看看