网页计算器

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <style>

         html,body {

            margin: 0px;

            padding: 0px;

            background-color: rgb(156, 212, 238);

        }

        p{

            font-size: 30px ;

            font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;

            text-align: center;

            padding-right: 100px;

            margin-top: 28px;

            font-weight:bold;

        }

        .container {

            width: 435px;

            height: 480px;

            margin-left: 500px;

            margin-top: 30px;

            background-color: #f8a1a9;

            border: 1px solid black;

        }

        table {

            width: 390px;

            height: 380px;

            margin-left: 22px;

            border: 1px solid rgb(116, 43, 212);

            background-color: #e2ebb4;

        }

       

        input {

            margin-top: 20px;

            margin-left: 24px;

            width: 378px;

            height: 38px;

            opacity: 0.6;

            font-size: 20px;

            color: black;

            border-radius: 5px;

            margin-right: 5px;

            background-color: whitesmoke;

        }

        button{

            width: 60px;

            height: 50px;

            margin-top: 15px;

            text-align: center;

            margin-left: 25px;

            border-radius: 10px;

            font:16px black bold;

            border: 1px solid black;

            background-color: rgb(211, 207, 207);

            box-shadow: 2px 2px  rgb(0, 0, 0);

            cursor: pointer;

        }

        button:hover{

            background-color: rgb(31, 28, 28);

            color: whitesmoke;

        }

    </style>

</head>

<body>

    <hr>

    <p>计&nbsp;算&nbsp;器</p>

   

    <div class="container">

       

        <table>

            <input type="text" name="look" id="look"><br><br>

            <tr>

                <td><button value="CE" οnclick="cle()">CE</button></td>

                <td><button value="+" οnclick="compute(this)">+</button></td>

                <td><button value="-" οnclick="compute(this)">-</button></td>

                <td><button value="DEL" οnclick="del()">DEL</button></td>

            </tr>

            <tr>

                <td><button value="7" οnclick="compute(this)">7</button></td>

                <td><button value="8" οnclick="compute(this)">8</button></td>

                <td><button value="9" οnclick="compute(this)">9</button></td>

                <td><button value="*" οnclick="compute(this)">*</button></td>

            </tr>

            <tr>

                <td><button value="4" οnclick="compute(this)">4</button></td>

                <td><button value="5" οnclick="compute(this)">5</button></td>

                <td><button value="6" οnclick="compute(this)">6</button></td>

                <td><button value="/" οnclick="compute(this)">/</button></td>

            </tr>

            <tr>

                <td><button value="1" οnclick="compute(this)">1</button></td>

                <td><button value="2" οnclick="compute(this)">2</button></td>

                <td><button value="3" οnclick="compute(this)">3</button></td>

                <td><button value="." οnclick="compute(this)">.</button></td>

            </tr>

            <tr>

                <td><button value="(" οnclick="compute(this)">(</button></td>

                <td><button value="0" οnclick="compute(this)">0</button></td>

                <td><button value=")" οnclick="compute(this)">)</button></td>

                <td><button value="=" οnclick="result()">=</button></td>

            </tr>

        </table>

    </div>

    <script>

        function compute(show){

            document.getElementById("look").value+=show.value;

        }

        function cle(){

            document.getElementById("look").value=null;

        }

        function del(){

            var num = document.getElementById("look");

            num.value = num.value.substring(0,num.value.length-1);

        }

        function result(){

            str = document.getElementById("look");

            numresult = eval(str.value);

            str.value = numresult

                 

        }

    </script>

</body>

</html>

效果图:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值