Blogger Information
Blog 70
fans 4
comment 5
visits 103794
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP:使用定界符输出九格宫表格,颜色各异,每个小格子宽高50px ,用php实现具有简单功能的计算器
JiaJieChen
Original
840 people have browsed it

PHP:使用定界符输出九格宫表格,颜色各异,每个小格子宽高50px 用php实现具有简单功能的计算器

一.使用定界符输出九格宫表格,颜色各异,每个小格子宽高50px

代码块

       
  1. php
  2. //输出颜色不一样的九宫格
  3. //随机颜色
  4. for($i=0;$i<3;$i++){
  5. $td="";
  6. for($a=0;$a<3;$a++){
  7. $r=mt_rand(0,255);
  8. $g=mt_rand(0,255);
  9. $b=mt_rand(0,255);
  10. $td.=<<<td
  11. <td style='background-color:rgb($r,$g,$b);'>td>
  12. td;
  13. }
  14. $tr.=<<<tr
  15. $td
  16. tr>
  17. tr;
  18. }
  19. echo<<<table
  20. <table border="1"cellspacing="0"width="150"height="150">
  21. $tr
  22. table>
  23. table;

二.用php实现具有简单功能的计算器

代码块

       
  1. lang="en">
  2. charset="UTF-8">
  3. http-equiv="X-UA-Compatible"content="IE=edge">
  4. name="viewport"content="width=device-width, initial-scale=1.0">
  5. </span><span class="pln">简单计算器</span><span class="tag">
  6. php
  7. //判断用户是否点击了计算按钮
  8. if(isset($_POST['submit'])){
  9. //判断用户除数不能为0
  10. if($_POST['option']=='/'&&$_POST['number2']==0||$_POST['option']=='%'&&$_POST['number2']==0){
  11. //设置一个变量来储存输出的字符
  12. $tips='

    除数不能为0

    '
    ;
  13. }
  14. }
  15. ?>
  16. class="box">
  17. colspan="4">简单计算器
  18. action=""method="POST">
  19. colspan="4">
  20. php
  21. //判断 $tips 是否为0 是则输出语句 否则执行计算功能
  22. if(!$tips){
  23. switch($_POST['option']){
  24. case"+":
  25. //int 临时转换为数值类型
  26. $sum=(int)$_POST['number1']+(int)$_POST['number2'];
  27. break;
  28. case"-":
  29. $sum=(int)$_POST["number1"]-(int)$_POST['number2'];
  30. break;
  31. case"*":
  32. $sum=(int)$_POST["number1"]*(int)$_POST['number2'];
  33. break;
  34. case"/":
  35. $sum=(int)$_POST["number1"]/(int)$_POST['number2'];
  36. break;
  37. case"%":
  38. $sum=(int)$_POST["number1"]%(int)$_POST['number2'];
  39. break;
  40. }
  41. //计算结果通知到用户
  42. $tipss="计算结果: {$_POST['number1']} {$_POST['option']} {$_POST['number2']} = {$sum} ";
  43. echo"

    $tipss

    "
    ;
  44. }else{
  45. echo $tips;
  46. }
  47. ?>
  48. $_POST["number1"]?>" >
  49. name="option">
  50. $_POST["number2"]?>" >
  51. type="submit"name="submit"value="计算">
  • 三.用javaScript实现具有简单功能的计算器

    代码块

           
    1. lang="en">
    2. charset="UTF-8"/>
    3. http-equiv="X-UA-Compatible"content="IE=edge"/>
    4. name="viewport"content="width=device-width, initial-scale=1.0"/>
    5. </span><span class="pln">计算器</span><span class="tag">
    6. rel="stylesheet"href="jsq.css"/>
    7. class="jsq">
    8. cellspacing="0";>
    9. colspan="4">计算器
    10. colspan="4">
    11. for="">type="text"value=""/>
    12. for="">value="7">7
    13. for="">value="8">8
    14. for="">value="9">9
    15. for="">value="/"class="devide">/
    16. for="">value="4">4
    17. for="">value="5">5
    18. for="">value="6">6
    19. for="">value="*"class="take">*
    20. for="">value="1">1
    21. for="">value="2">2
    22. for="">value="3">3
    23. for="">value="-"class="minus">-
    24. for="">value="0">0
    25. for="">value=".">.
    26. for="">value=""class="sum">=
    27. for="">value="+"class="add">+
    28. colspan="4">
    29. for=""
    30. >style="width:250px"type="reset"class="reset">
    31. 重置
    32. >
  • 单击->进入计算器模拟测试

    http://www.zwzgjl.com/error/jsq/jsq.html

    Correcting teacher:灭绝师太灭绝师太

    Correction status:qualified

    Teacher's comments:买个小服务器做测试还是不错的~
    Statement of this Website
    The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
    All comments Speak rationally on civilized internet, please comply withNews Comment Service Agreement
    0 comments
    Author's latest blog post
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!