方法一·<input type="hidden" name="doing" value="work"> Cat.php <form action="CatWork.php" method="post"> <h1>四则运算</h1> 第一个数:<input type="text" name="num1"><br> 第二个数:<input type="text" name="num2"><br> 运算符号: <select name="oper"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select><br> //隐藏域的使用 <input type="hidden" name="doing" value="work"> <input type="submit" value="开始计算"> </form> <br> <form action="CatWork.php" method="post"> <h1>计算圆形面积</h1> 请输入半径:<input type="text" name="radius"><br> <input type="submit" value="开始计算面积"> //隐藏域的使用 <input type="hidden" name="doing" value="area"> </form> <form action="CatWork.php" method="post"> <h1>长方形的面积</h1> 长:<input type="text" name="length"><br> 宽:<input type="text" name="width"><br> 隐藏域的使用 <input type="hidden" name="doing" value="rectangle"><br> <input type="submit" value="开始计算"> </form> CatWork.php <?php require_once 'CatClass.php'; $doing=$_REQUEST['doing']; $cat=new Cat(); if($doing=="work"){ $num1=$_REQUEST['num1']; $num2=$_REQUEST['num2']; $oper=$_REQUEST['oper']; echo '计算结果:'.$cat->work($num1,$num2,$oper)."<br>"; }elseif($doing=="area"){ $radius=$_REQUEST['radius']; echo '计算面积是'.$cat->circleArea($radius); }elseif($doing=="rectangle"){ $length=$_REQUEST['length']; $width=$_REQUEST['width']; //var_dump($length,$width); echo '长方形的面积是:'.$cat->rectangleArea($length,$width); } echo "<br>"; echo "<a href='Cat.php'>返回主页</a>"; ?> CatWork.php <?php header("content-type:text/html;charset=utf8"); class Cat{ $res=0; function work($num1,$num2,$oper){ if($oper=="+"){ $res=$num1+$num2; }elseif($oper=="-"){ $res=$num1+$num2; }elseif($oper=="*"){ $res=$num1*$num2; }elseif($oper=="/"){ $res=$num1/$num2; } return $res; } function circleArea($radius){ return 3.14*$radius*$radius; } function rectangleArea($l,$w){ return $l*$w; } } ?> 方法二· <html> <head> <meta http-equiv="content-type" content="text/html charset=utf-8"> <script language="javascript"> function selType(val){ //window.alert("你选中"+val); if(val=="jisuan"){ table1.style.display="block"; table2.style.display="none"; }else if(val=="area"){ table1.style.display="none"; table2.style.display="block"; } } </script> </head> <h1>聪明的猫</h1> <form action="CatWork.php" method="post"> <input type="radio" name="sel" οnclick="selType('jisuan')">四则运算 <input type="radio" name="sel" οnclick="selType('area')">计算矩形 <table id="table1" style="display:black"> <tr><td>第一个数</td><td><input type="text" name="num1"></td></tr> <tr><td>第二个数</td><td><input type="text" name="num2"></td></tr> <tr><td>运算符号</td> <td> <select name="oper"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> </td> </tr> <tr><td colspan="2"><input type="submit" value="四则运算"></td></tr> </table> <table id="table2" style="display:none"> <tr><td>长</td><td><input type="text" name="length"></td></tr> <tr><td>宽</td><td><input type="text" name="width"></td></tr> <tr><td colspan="2"><input type="submit" value="矩形运算"></td></tr> </table> </form> </html>