zoukankan      html  css  js  c++  java
  • php写一个简单的计算器

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>计算器</title>
    </head>
    <body>
    <form  method="post">
        <table  align="center">
            <tr>
                <td  align="center">第一个数</td><td><input type="text" name="first"></td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="radio" name="operator" value="+">+
                    <input type="radio" name="operator" value="-">-
                    <input type="radio" name="operator" value="*">*
                    <input type="radio" name="operator" value="/">/
                </td>
            </tr>
            <tr>
                <td  align="center">第二个数</td><td><input type="text" name="second"></td>
            </tr>
            <tr>
                <td> <input type="submit" value="提交"></td>
            </tr>
        </table>
    </form>
    <?php
    header("content-type:text/html;charset=utf-8");
        $first=$_POST['first'];
        $second=$_POST['second'];
        $operator=$_POST['operator'];
        echo '结果为:';
        if ( $operator == '+' )
        {
            echo $first+$second;
        }
        if($operator == '-')
        {
            echo $first-$second;
        }
        if($operator == '*')
        {
            echo $first*$second;
        }if($operator == '/')
        {
            echo $first/$second;
        }
        ?>
    </body>
    </html>

     这个会报警告:

    上网查了一下,因为接收了空值,所以报的这个警告。

    所以这个东西可以不用管。

    解决方法:

    https://www.baidu.com/link?url=gy5XGLhoRy8bUMPZLMcTGuWl7nQKAXt9Zrn642HRBhAcZS5oRax1KFrga5IqAxzXlKs5Xv3qGnc68AjakEKIW_&wd=&eqid=bb0491f00000160a000000025ae170a7

    运行结果:

    https://necydcy.me/
  • 相关阅读:
    ES6 快速入门
    export,import ,export default区别
    React 生命周期
    Nodejs npm常用命令
    JavaScript:改变 HTML 图像
    WebStorm安装、配置node.js(Windows)
    Flex 布局
    块级元素与行内元素区别
    自动化测试弹框处理
    python远程操作服务器
  • 原文地址:https://www.cnblogs.com/miria-486/p/8952125.html
Copyright © 2011-2022 走看看