HTML+CSS+JS实现简单计算器

本文展示了如何利用前端技术HTML、CSS和JavaScript创建一个简易计算器。内容包括设计计算器界面,通过JavaScript实现基本的加、减、乘、除、清屏、退格、取余、取倒数等运算功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      本文运用前端代码实现一个简单的计算器界面,并通过JS实现了基本的运算功能。(加、减、乘、除、清屏/退格、取余、取倒)

1.编写前端界面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的计算器</title>
    <style>
        .containor{
            border:1px solid black;
            background-color: #fafafa;
            height: 380px;
            width: 296px;
            margin: auto;
            margin-top: 40px;
        }
        .top{
            background-color: lightgray;
            height: 30px;
        }
        a{
            display: block;
            float: left;
            font-size: 8px;
            height: 26px;
            padding: 0 6px;
            margin-left: 6px;
            line-height: 26px;
        }

        a:hover{
            background-color: dimgray;
            color: white;
            cursor: default;
        }

        .input{
            width: 86%;
            height:60px;
            padding: 4px;
            margin: 0 auto;
            margin-top: 12px;
        }
        .input:focus{
            outline: none;
        }
        button{
            width: 50px;
            height: 30px;
            margin: 2px;
            text-align: center;
            font-size: 10px;
            border: 0.5px solid gray;

        }
        button:hover{
            border: 1px solid gray;
            background-color: #ffaa55;
            outline: none;
        }
        .bottom{
            width: 100%;
            height: 30px;
            background-color:lightgray;
            color: white;
            position: relative;
            margin-top: 5
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值