找回密码
 新建账号

[PHP] PHP九九乘法表,梯形99乘法表,方形99乘法表

[复制链接]
php 发表于 2012/6/3 19:01 | 显示全部楼层 |阅读模式
PHP编写的九九乘法表.梯形和方形九九乘法表.将每一个乘法式都放在表格里面,界面美观不凌乱.

  1. <!doctype HTML>
  2. <html>
  3. <head>
  4. <title>九九乘法表</title>
  5. <style type="text/css">
  6. body{
  7.         background:#F5F5DC;
  8. }
  9. table,td{
  10.         border:none;
  11. }
  12. td{
  13.         width:80px;
  14.         height:30px;
  15.         text-align:center;
  16.         color:red;
  17. }
  18. .trbg{
  19.         background:#ffe4c4;
  20. }
  21. .tdbg{
  22.         background:#00fa9a;
  23.         cursor:pointer;
  24. }
  25. .trbgg{
  26.         background:#e9967a;
  27. }
  28. caption{
  29.         color:#b8860b;
  30. }
  31. </style>
  32. </head>
  33. <?php
  34. $line=str_repeat('-',24);
  35. ?>
  36. <body>
  37. <table>
  38. <caption><?php echo $line.'梯形九九乘法表'.$line ?></caption>
  39. <?php
  40. for($i=1;$i<=9;$i++){
  41.         $color=$i%2==0 ? ' trbg' : 'trbgg';
  42.         echo '<tr class="'.$color."">\n";
  43.         for($j=1;$j<=$i;$j++){
  44.                 echo '<td>'.$j.'*'.$i.'='.$j*$i."</td>\n";
  45.         }
  46.         echo "</tr>\n";
  47. }
  48. ?>
  49. </table>
  50. <table>
  51. <caption><?php echo $line.'方形九九乘法表'.$line ?></caption>
  52. <?php
  53. for($i=1;$i<=9;$i++){
  54.         $color=$i%2==1 ? ' trbg' : 'trbgg';
  55.         echo '<tr class="'.$color."">\n";
  56.     for($j=1;$j<=9;$j++){
  57.                 echo " <td>$i*$j=".$i*$j."</td>\n";
  58.     }
  59.     echo "</tr>\n";
  60. }
  61. ?>
  62. </table>
  63. <a id="link"></a>
  64. <script type="text/javascript">
  65. var td=document.getElementsByTagName('td');
  66. for(var i in td){
  67.         if(typeof(td[i]=='object')){
  68.                 td[i].onmouseover=function(){
  69.                         this.className='tdbg';
  70.                         this.title=this.innerHTML;
  71.                         this.onclick=function(){
  72.                                 if(confirm(this.innerHTML + '\r\n是否需要了解更多?')){
  73.                                         var link=document.getElementById('link');
  74.                                         link.href='http://www.51-n.com/';
  75.                                         link.click();
  76.                                 }
  77.                         }
  78.                 }
  79.                 td[i].onmouseout=function(){
  80.                         if(!document.all){
  81.                                 this.removeAttribute('class');
  82.                                 this.removeAttribute('title');
  83.                         }else{
  84.                                 this.className='';
  85.                                 this.title='';
  86.                         }
  87.                 }
  88.         }
  89. }
  90. </script>
  91. </body>
  92. </html>
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?新建账号

×

手机版|轻松E站

GMT+8, 2024/3/29 23:04

快速回复 返回顶部 返回列表