JavaScript: 制作简单计算器

效果图如下:

简单计算器

下面来讲讲我的思路:
简单的说就是利用HTML与CSS制作出一个计算器的外观,然后通过js来实现用户与计算器之间的交互,进而实现简单的计算。

对于HTML:
According to semantic HTML, I use <bottom>to represent every button, using <input> to display the result.

对于CSS:
I use gradual color to decorate my calculator, together with different color of button, special font-family of result, motivating the real calculator to the greatest extent.

对于JavaScript:
First, set the property of buttons — onclick().
Then make good use of the function of eval(), which can not only test whether the arithmetic expression is valid, but also deal with the expression and display the result.

下面是我的代码:

HTML:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Calculator</title>
        <link rel="stylesheet" type="text/css" href="style.css">
        <script type="text/javascript" src="calculate.js"></script>
    </head>
    <body>
        <h1 id="title">小威威de计算器</h1>
        <div id="calculator_container">
            <div id="calculator">
                <input type="result" disabled="disabled" id="result">
                <div id="first_row">
                    <button id="seven" class="button">7</button>
                    <button id="eight" class="button">8</button>
                    <button id="nine" class="button">9</button>
                    <button id="divide" class="button">/</button>
                </div>
                <div id="second_row">
                    <button id="four" class="button">4</button>
                    <button id="five" class="button">5</button>
                    <button id="six" class="button">6</button>
                    <button id="multiply" class="button">*</button>
                </div>
                <div id="third_row">
                    <button id="one" 
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值