简易计算器

这是一个使用HTML、CSS和JavaScript实现的简易计算器网页。网页背景和计算器界面设计简洁,按钮布局清晰,支持基本的数学运算及清除、删除、小数点和等号功能。用户点击按钮即可在输入框中显示相应的数字或运算符,最后通过等号按钮得到计算结果。
摘要由CSDN通过智能技术生成

样式:

<!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(175, 119, 119);
        }
        p{
            font-size: 32px ;
            font-family:serif;
            text-align: center;
            margin-top: 30px;
            font-weight:bold;
        }
        .container {
            width: 430px;
            height: 500px;
            margin-left: 560px;
            margin-top: 30px;
            background-color: #5a5959;
            border: 1px solid black;
        }
        table {
            width: 390px;
            height: 380px;
            margin-left: 22px;
            border: 1px solid rgb(0, 0, 0);
            background-color: #666666;
        }
        
        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: 48px;
            height: 36px;
            margin-top: 16px;
            text-align: center;
            margin-left: 23px;
            /* margin-bottom: 8px; */
            border-radius: 6px;
            font:14px 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>
    <!-- js练习  实现网页版计算器 -->
    <p>简&nbsp;易&nbsp;计&nbsp;算&nbsp;器</p>
   
    <div class="container">
       
        <table>
            <input type="text" name="look" id="look"><br><br>
            <tr>
                <td><button value="CE" onclick="cle()">CE</button></td>
                <td><button value="+" onclick="compute(this)">+</button></td>
                <td><button value="-" onclick="compute(this)">-</button></td>
                <td><button value="DEL" onclick="del()">DEL</button></td>
            </tr>
            <tr>
                <td><button value="7" onclick="compute(this)">7</button></td>
                <td><button value="8" onclick="compute(this)">8</button></td>
                <td><button value="9" onclick="compute(this)">9</button></td>
                <td><button value="*" onclick="compute(this)">*</button></td>
            </tr>
            <tr>
                <td><button value="4" onclick="compute(this)">4</button></td>
                <td><button value="5" onclick="compute(this)">5</button></td>
                <td><button value="6" onclick="compute(this)">6</button></td>
                <td><button value="/" onclick="compute(this)">/</button></td>
            </tr>
            <tr>
                <td><button value="1" onclick="compute(this)">1</button></td>
                <td><button value="2" onclick="compute(this)">2</button></td>
                <td><button value="3" onclick="compute(this)">3</button></td>
                <td><button value="." onclick="compute(this)">.</button></td>
            </tr>
            <tr>
                <td><button value="(" onclick="compute(this)">(</button></td>
                <td><button value="0" onclick="compute(this)">0</button></td>
                <td><button value=")" onclick="compute(this)">)</button></td>
                <td><button value="=" onclick="result()">=</button></td>
            </tr>
        </table>
    </div>
    

 script

<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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值