8)post方式提交和简单那处理
带有htmll的代码:
实现简单的计算器
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 5 <title>网页标题</title> 6 <meta name="keywords" content="关键字列表" /> 7 <meta name="description" content="网页描述" /> 8 <link rel="stylesheet" type="text/css" href="" /> 9 <style type="text/css"></style> 10 <script type="text/javascript"></script> 11 </head> 12 <body> 13 <form action="5post_2.php" method="post" > 14 <input type="text" name="n1" /> 15 <select name="yunsuanfu" > 16 <option value="+" >+</option> 17 <option value="-" >-</option> 18 <option value="*" >*</option> 19 <option value="/" >/</option> 20 </select> 21 <input type="text" name="n2" /> 22 <input type="submit" value="提交" /> 23 </form> 24 </body> 25 </html>
PHP处理代码:
1 <?php 2 /** 3 * Created by PhpStorm. 4 * User: Interact 5 * Date: 2017/4/13 6 * Time: 21:31 7 */ 8 9 $v1=$_POST['n1']; 10 $v2=$_POST['n2']; 11 $fuhao=$_POST['yunsuanfu']; 12 if($fuhao==='+'){ 13 echo $v1+$v2; 14 }elseif($fuhao==='-'){ 15 echo $v1-$v2; 16 17 }elseif($fuhao==='*'){ 18 echo $v1*$v2; 19 } 20 else{ 21 echo $v1%$v2; 22 } 23 24 25 26