jQuery如何实现简单计算器特效
沉沙 2018-06-28 来源 : 阅读 2116 评论 0

摘要:本篇教程通过代码讲解了jQuery如何实现简单计算器特效,该jQuery计算器使用 Bootstrap 4进行布局,并结合math.js数学库,实现简单的加减乘除和平方,开方等数学计算。

简要教程

这是一款jquery实现简单计算器代码。该jquery计算器使用 Bootstrap 4进行布局,并结合math.js数学库,实现简单的加减乘除和平方,开方等数学计算。

 使用方法

在页面中引入bootstrap 4,jquery和math.min.js文件。以及计算器的样式文件style.css和main.js文件。


<link href="path/to/bootstrap-4.0.0-beta.min.css" rel="stylesheet">                       
<link href="path/to/font-awesome.min.css" rel="stylesheet">                 
<link href="path/to/style.css" rel="stylesheet">
<script src="path/to/jquery.js"></script>
<script src="path/to/bootstrap-4.0.0-beta.min.js"></script>
<script src="path/to/math.min.js"></script>
<script src="path/to/main.js"></script>

  

 HTML结构

该jquery计算器的HTML结构如下:

<div class="container">
    <!-- Rounded switch -->
    <label class="switch">
        <input type="checkbox">
        <span class="slider"></span>
    </label>
    <form>
        <input readonly id="display1" type="text" class="form-control-lg text-right">
        <input readonly id="display2" type="text" class="form-control-lg text-right">
    </form>
     
    <div class="d-flex justify-content-between button-row">
        <button id="left-parenthesis" type="button" class="operator-group">(</button>
        <button id="right-parenthesis" type="button" class="operator-group">)</button>
        <button id="square-root" type="button" class="operator-group">√</button>
        <button id="square" type="button" class="operator-group">x²</button>
    </div>
   
    <div class="d-flex justify-content-between button-row">
        <button id="clear" type="button">C</button>
        <button id="backspace" type="button">⌫</button>
        <button id="ans" type="button" class="operand-group">Ans</button>
        <button id="divide" type="button" class="operator-group">÷</button>
    </div>
     
 
    <div class="d-flex justify-content-between button-row">
        <button id="seven" type="button" class="operand-group">7</button>
        <button id="eight" type="button" class="operand-group">8</button>
        <button id="nine" type="button" class="operand-group">9</button>
        <button id="multiply" type="button" class="operator-group">×</button>
    </div>
 
     
    <div class="d-flex justify-content-between button-row">
        <button id="four" type="button" class="operand-group">4</button>
        <button id="five" type="button" class="operand-group">5</button>
        <button id="six" type="button" class="operand-group">6</button>
        <button id="subtract" type="button" class="operator-group">−</button>
    </div>
 
     
    <div class="d-flex justify-content-between button-row">
        <button id="one" type="button" class="operand-group">1</button>
        <button id="two" type="button" class="operand-group">2</button>
        <button id="three" type="button" class="operand-group">3</button>
        <button id="add" type="button" class="operator-group">+</button>
    </div>
 
    <div class="d-flex justify-content-between button-row">
        <button id="percentage" type="button" class="operand-group">%</button>
        <button id="zero" type="button" class="operand-group">0</button>
        <button id="decimal" type="button" class="operand-group">.</button>
        <button id="equal" type="button">=</button>
    </div>
 
</div>

   

本文由职坐标整理发布,欢迎关注职坐标WEB前端jQuery频道,获取更多jQuery知识!

本文由 @沉沙 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程