With JavaScript to achieve a similar two tab switching effect, with object-oriented programming approach, to achieve arithmetic and calculate the rectangular area:
catview.php:
<meta http-equiv= "Content-type" content= "TEXT/HTML;CHARSET=GBK"/>
<script language= "JavaScript" >
<!--
Function SelType (val) {
if (val== ' Jishuan ') {
Displays the interface of the arithmetic, while hiding the interface of the computed rectangle
table1.style.display= "Block";
Table2.style.display= "None";
}else if (val== ' area ') {
Displays the interface of the computed rectangle while hiding the arithmetic interface
Table1.style.display= "None";
table2.style.display= "Block";
}
}
-->
</script>
<body>
<form action= "catwork.php" method= "POST" >
<input type= "Radio" name= "sel" value= "AA" onclick= "SelType" (' Jishuan ') "> Arithmetic
<input type= "Radio" name= "sel" value= "BB" onclick= "seltype (' area ')" > Compute Rectangle
<table id= "table1" style= "Display:block" >
<tr><td> Please enter the first number: </td><td><input type= "text" name= "NUM1" ></td></tr>
<tr><td> Please enter a second number: </td><td><input tyep= "text" name= "num2" ></td></tr>
<tr><td> Please select operator: </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= "Arithmetic" ></td></tr>
</table>
<!--The following table is used to display the computed rectangle-->
<table id= "table2" style= "Display:none" >
<tr><td> Please enter long: </td><td><input type= "text" name= "Long" ></td></tr>
<tr><td> Please input width: </td><td><input type= "text" name= "WID" ></td></tr>
<TR><TD colspan= "2" ><input type= "Submit" value= "Start operation" ></td></tr>
</table>
</form>
</body>
catwork.php:
<?php
Receive data
Receive num1,num2, operator symbol
Require_once ' Cat.class.php ';
First receive doing
$sel = $_request[' sel '];
$cat 1 = new Cat ();
if ($sel = = "AA") {
$num 1 = $_request[' num1 '];
$num 2 = $_request[' num2 '];
$oper = $_request[' oper '];
$res = $cat 1->jishuan ($num 1, $num 2, $oper);
echo "The result is:". $res. "<br/>";
else if ($sel = = "BB") {
$long = $_request[' long '];
$wid = $_request[' wid '];
echo "The result is:". $cat 1->juxingarea ($long, $wid);
}
?>
<br/><a href= "catview.php" > Return to Main interface </a>
Cat.class.php:
<?php
Defining classes
Class Cat {
function Juxingarea ($long, $wid) {
return $long * $WID;
}
function Jishuan ($num 1, $num 2, $oper) {
Switch ($oper) {
Case "+":
return $num 1 + $num 2;
Break
Case "-":
Return $num 1-$num 2;
Break
Case "*":
Return $num 1 * $num 2;
Break
Case "/":
return $num 1/$num 2;
Break
}
}
}
?>