求问php大佬 为什么我这个计算器出不来结果
<html><body><head><metahttp-equiv="content-type"content="text/html;char-set-ysf"><tit...
<html>
<body>
<head>
<meta http-equiv="content-type" content="text/html;char-set-ysf">
<title>PHP实现的简单计算器</title>
</head>
<body>
<table align="center" border="1" width="500">
<caption><br>计算器</br><caption>
<form action "jsq.php" method="post">
<tr>
<td>
<input type="text" size="15" name="num1" value=""/>
<select name="ysf">
<option value ="+">+</option>
<option value ="-">-</option>
<option value ="x">x</option>
<option value ="/">/</option>
<option value ="%">%</option>
</select>
<input type="text" size="15" name="num2" value=""/>
=
<input type="text" size="15" name="sub" value=""
<?php
if(count($_POST) != 0){
switch($_POST['ysf']){
case"+":
$sum=$_POST['num1']+($_POST['num2']);
break;
case"-":
$sum=$_POST['num1']-($_POST['num2']);
break;
case"x":
$sum=$_POST['num1']*($_POST['num2']);
break;
case"/":
$sum=$_POST['num1']/($_POST['num2']);
break;
case"%":
$sum=$_POST['num1']%($_POST['num2']);
break;
}
}
?>
<input type="submit" value="计算" >
</form>
</body>
</html> 展开
<body>
<head>
<meta http-equiv="content-type" content="text/html;char-set-ysf">
<title>PHP实现的简单计算器</title>
</head>
<body>
<table align="center" border="1" width="500">
<caption><br>计算器</br><caption>
<form action "jsq.php" method="post">
<tr>
<td>
<input type="text" size="15" name="num1" value=""/>
<select name="ysf">
<option value ="+">+</option>
<option value ="-">-</option>
<option value ="x">x</option>
<option value ="/">/</option>
<option value ="%">%</option>
</select>
<input type="text" size="15" name="num2" value=""/>
=
<input type="text" size="15" name="sub" value=""
<?php
if(count($_POST) != 0){
switch($_POST['ysf']){
case"+":
$sum=$_POST['num1']+($_POST['num2']);
break;
case"-":
$sum=$_POST['num1']-($_POST['num2']);
break;
case"x":
$sum=$_POST['num1']*($_POST['num2']);
break;
case"/":
$sum=$_POST['num1']/($_POST['num2']);
break;
case"%":
$sum=$_POST['num1']%($_POST['num2']);
break;
}
}
?>
<input type="submit" value="计算" >
</form>
</body>
</html> 展开
2个回答
展开全部
你PHP code无法做到实时获取,你先了解下表单提交和$_POST.
提供个思路,你可以讲PHP code写在单独文件中,通过js判断俩个输入框是否有值
判断成功后通过ajax与PHP交互获取值动态添加到结果框中
提供个思路,你可以讲PHP code写在单独文件中,通过js判断俩个输入框是否有值
判断成功后通过ajax与PHP交互获取值动态添加到结果框中
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
中智咨询
2024-08-28 广告
2024-08-28 广告
在当今竞争激烈的商业环境中,企业需要不断提高自身的竞争力,以保持市场份额和增加利润。通过人效提升,企业可以更有效地利用有限的资源,提高生产力和效益,从而实现盈利目标。中智咨询提供全方位的组织人效评价与诊断、人效提升方案等数据和管理咨询服务。...
点击进入详情页
本回答由中智咨询提供
展开全部
我给你的代码简单改了改,你可以运行一下,在看看代码。
<html>
<body>
<head>
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html;char-set-ysf">
<title>PHP实现的简单计算器</title>
</head>
<body>
<table align="center" border="1" width="500">
<caption><br>计算器</br><caption>
<form action "jsq.php" method="post">
<tr>
<td>
<?php
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$ysf = $_POST['ysf'];
if(count($_POST) != 0){
switch($_POST['ysf']){
case"+":
$sum=$_POST['num1']+($_POST['num2']);
break;
case"-":
$sum=$_POST['num1']-($_POST['num2']);
break;
case"x":
$sum=$_POST['num1']*($_POST['num2']);
break;
case"/":
$sum=$_POST['num1']/($_POST['num2']);
break;
case"%":
$sum=$_POST['num1']%($_POST['num2']);
break;
}
}
?>
<input type="text" size="15" name="num1" value="<?php echo $num1;?>"/>
<select name="ysf">
<option value ="+" <?php if($ysf == '+'){echo 'selected="selected"';} ?>>+</option>
<option value ="-" <?php if($ysf == '-'){echo 'selected="selected"';} ?>>-</option>
<option value ="x" <?php if($ysf == 'x'){echo 'selected="selected"';} ?>>x</option>
<option value ="/" <?php if($ysf == '/'){echo 'selected="selected"';} ?>>/</option>
<option value ="%" <?php if($ysf == '%'){echo 'selected="selected"';} ?>>%</option>
</select>
<input type="text" size="15" name="num2" value="<?php echo $num2;?>"/>
=
<input type="text" size="15" name="sub" value="<?php echo $sum;?>" />
<input type="submit" value="计算" >
</form>
</body>
</html>
<html>
<body>
<head>
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html;char-set-ysf">
<title>PHP实现的简单计算器</title>
</head>
<body>
<table align="center" border="1" width="500">
<caption><br>计算器</br><caption>
<form action "jsq.php" method="post">
<tr>
<td>
<?php
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$ysf = $_POST['ysf'];
if(count($_POST) != 0){
switch($_POST['ysf']){
case"+":
$sum=$_POST['num1']+($_POST['num2']);
break;
case"-":
$sum=$_POST['num1']-($_POST['num2']);
break;
case"x":
$sum=$_POST['num1']*($_POST['num2']);
break;
case"/":
$sum=$_POST['num1']/($_POST['num2']);
break;
case"%":
$sum=$_POST['num1']%($_POST['num2']);
break;
}
}
?>
<input type="text" size="15" name="num1" value="<?php echo $num1;?>"/>
<select name="ysf">
<option value ="+" <?php if($ysf == '+'){echo 'selected="selected"';} ?>>+</option>
<option value ="-" <?php if($ysf == '-'){echo 'selected="selected"';} ?>>-</option>
<option value ="x" <?php if($ysf == 'x'){echo 'selected="selected"';} ?>>x</option>
<option value ="/" <?php if($ysf == '/'){echo 'selected="selected"';} ?>>/</option>
<option value ="%" <?php if($ysf == '%'){echo 'selected="selected"';} ?>>%</option>
</select>
<input type="text" size="15" name="num2" value="<?php echo $num2;?>"/>
=
<input type="text" size="15" name="sub" value="<?php echo $sum;?>" />
<input type="submit" value="计算" >
</form>
</body>
</html>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询