实例

隐藏表单的魅力

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
<form action="3.php" method="post">
<h1>四则运算</h1>
<br/>
<input type="text" name="first" value="0"/>
<select name="expr">
<option name="add" selected="selected">+</option>
<option name="dec">-</option>
<option name="multi">*</option>
</select>
<input type="text" name="second" value="0"/>
<!--隐藏表单-->
<input type="hidden" name="doing" value="arithmetic"/>
<input type="submit" name="clac" value="计算"/>
</form>

<form action="3.php" method="post">
<h1>圆面积运算</h1>
<br/>
请输入半径:<input type="text" name="radius" value="0"/>
<!--隐藏表单-->
<input type="hidden" name="doing" value="area"/>
<input type="submit" name="clac" value="计算"/>
</form>
</body>
</html>
<html>
<body>
<?php
	require_once 'Calc.class.php';
	$select=$_REQUEST['doing'];
	if($select=="arithmetic"){
		$result=new Calc();
		$num1=$_REQUEST['first'];
		$num2=$_REQUEST['second'];
		$oper=$_REQUEST['expr'];
		$result->Arithmetic($num1,$num2,$oper);
	}else if($select=="area"){
		$result=new Calc();
		$radius=$_REQUEST['radius'];
		$result->circleArea($radius);
	}
?>
<br/>
<a href="2.php">主界面</a>
</body>
</html>
<?php
	class Calc{
		public function Arithmetic($num1,$num2,$oper){
			switch($oper){
				case '+':
					echo "num1+num2=".($num1+$num2);
					break;
				case '-':
					echo "num1-num2=".($num1-$num2);
					break;
				case '*':
					echo "num1*num2=".($num1*$num2);
					break;
			}
		}
		public function circleArea($radius){
			echo "圆面积=".(3.14*$radius*$radius);
		}
	}
?>

在这里插入图片描述

js小技巧

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<script language="javascript">
<!--
	function selType(value){
		if(value=='arithmetic'){
			table1.style.display="block";
			table2.style.display="none";
		}else if(value=='area'){
			table1.style.display="none";
			table2.style.display="block";
		}
	}
//-->
</script>
</head>
<body>
<form action="3.php" method="post">
<input type="radio" name="selectCalc" value="arithmetic" onclick="selType('arithmetic')" checked="checked">四则运算</input>
<input type="radio" name="selectCalc" value="area" onclick="selType('area')">圆面积计算</input>
<br/>
<table id="table1" style="display: block;">
<tr>
<td><input type="text" name="first" value="0"/><td>
<td><select name="expr">
<option name="add" selected="selected">+</option>
<option name="dec">-</option>
<option name="multi">*</option>
</select></td>
<td><input type="text" name="second" value="0"/></td>
<td><input type="submit" name="clac" value="计算"/></td>
</tr>
</table>

<table id="table2" style="display: none">
<tr>
<td>请输入半径:<input type="text" name="radius" value="0"/></td>
<td><input type="submit" name="clac" value="计算"/></td>
</tr>
</table>
</form>
</body>
</html>

在这里插入图片描述
在这里插入图片描述

©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页