PHP做一个4个数字的计算器 跪求高手解答 急 先谢谢了!
1个回答
展开全部
<?
if($_SERVER['REQUEST_METHOD'] == "POST"){
switch (intval($_POST['ys'])) {
case 1:
$jg = intval($_POST['shu1']) + intval($_POST['shu2']);
break;
case 2:
$jg = intval($_POST['shu1']) - intval($_POST['shu2']);
break;
case 3:
$jg = intval($_POST['shu1']) * intval($_POST['shu2']);
break;
case 4:
$jg = intval($_POST['shu1']) / intval($_POST['shu2']);
break;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<input name="shu1" type="text" width="70" height="50" value="<?echo $_POST['shu1'];?>"/><br>
<input type="radio" name="ys" value="1" <?if($_POST['ys']==1) echo "checked='checked'"?>/>+
<input type="radio" name="ys" value="2" <?if($_POST['ys']==2) echo "checked='checked'"?>/>-
<input type="radio" name="ys" value="3" <?if($_POST['ys']==3) echo "checked='checked'"?>/>x
<input type="radio" name="ys" value="4" <?if($_POST['ys']==4) echo "checked='checked'"?>/>/<br>
<input name="shu2" type="text" width="70" height="50" value="<?echo $_POST['shu2'];?>"/><br>
<input type="submit" name="Submit" value="运算" /><?echo $jg;?>
</form>
</body>
</html>
if($_SERVER['REQUEST_METHOD'] == "POST"){
switch (intval($_POST['ys'])) {
case 1:
$jg = intval($_POST['shu1']) + intval($_POST['shu2']);
break;
case 2:
$jg = intval($_POST['shu1']) - intval($_POST['shu2']);
break;
case 3:
$jg = intval($_POST['shu1']) * intval($_POST['shu2']);
break;
case 4:
$jg = intval($_POST['shu1']) / intval($_POST['shu2']);
break;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<input name="shu1" type="text" width="70" height="50" value="<?echo $_POST['shu1'];?>"/><br>
<input type="radio" name="ys" value="1" <?if($_POST['ys']==1) echo "checked='checked'"?>/>+
<input type="radio" name="ys" value="2" <?if($_POST['ys']==2) echo "checked='checked'"?>/>-
<input type="radio" name="ys" value="3" <?if($_POST['ys']==3) echo "checked='checked'"?>/>x
<input type="radio" name="ys" value="4" <?if($_POST['ys']==4) echo "checked='checked'"?>/>/<br>
<input name="shu2" type="text" width="70" height="50" value="<?echo $_POST['shu2'];?>"/><br>
<input type="submit" name="Submit" value="运算" /><?echo $jg;?>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询