js html实现计算器功能


Posted in Javascript onNovember 13, 2018

本文实例为大家分享了html实现计算器功能的具体代码,供大家参考,具体内容如下

代码:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title></title>
  <script type="text/javascript">
 
    var numresult;
    var str;
    function onclicknum(nums)
    {
      str = document.getElementById("nummessege");
      str.value = str.value + nums;
    }
    function onclickclear()
    {
      str = document.getElementById("nummessege");
      str.value = "";
    }
    function onclickresult()
    {
      str = document.getElementById("nummessege");
      numresult = eval(str.value);
      str.value = numresult;
    }
  </script>
 
</head>
<body bgcolor="affff">
  <!--定义按键表格,每个按键对应一个事件触发-->
  <table border="1" align="center" bgColor="#bbff77"
      style="height: 350px; width: 270px">
    <tr>
      <td colspan="4">
        <input type="text" id="nummessege"
            style="height: 90px; width: 350px; font-size: 50px" />
      </td>
    </tr>
    <tr>
      <td>
        <input type="button" value="1" id="1" onclick="onclicknum(1)"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
      <td>
        <input type="button" value="2" id="2" onclick="onclicknum(2)"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
      <td>
        <input type="button" value="3" id="3" onclick="onclicknum(3)"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
      <td>
        <input type="button" value="+" id="add" onclick="onclicknum('+')"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
    </tr>
    <tr>
      <td>
        <input type="button" value="4" id="4" onclick="onclicknum(4)"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
      <td>
        <input type="button" value="5" id="5" onclick="onclicknum(5)"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
      <td>
        <input type="button" value="6" id="6" onclick="onclicknum(6)"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
      <td>
        <input type="button" value="-" id="sub" onclick="onclicknum('-')"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
    </tr>
    <tr>
      <td>
        <input type="button" value="7" id="7" onclick="onclicknum(7)"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
      <td>
        <input type="button" value="8" id="8" onclick="onclicknum(8)"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
      <td>
        <input type="button" value="9" id="9" onclick="onclicknum(9)"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
      <td>
        <input type="button" value="*" id="mul" onclick="onclicknum('*')"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <input type="button" value="0" id="0" onclick="onclicknum(0)"
            style="height: 70px; width: 190px; font-size: 35px">
      </td>
      <td>
        <input type="button" value="." id="point" onclick="onclicknum('.')"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
      <td>
        <input type="button" value="/" id="division"
            onclick="onclicknum('/')"
            style="height: 70px; width: 90px; font-size: 35px">
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <input type="button" value="Del" id="clear"
            onclick="onclickclear()"
            style="height: 70px; width: 190px; font-size: 35px" />
      </td>
      <td colspan="2">
        <input type="button" value="=" id="result"
            onclick="onclickresult()"
            style="height: 70px; width: 190px; font-size: 35px" />
      </td>
    </tr>
  </table>
</body>
</html>

效果图

js html实现计算器功能

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
javascript学习笔记(三) String 字符串类型介绍
Jun 19 Javascript
javascript面向对象之共享成员属性与方法及prototype关键字用法
Jan 13 Javascript
jquery.cookie.js实现用户登录保存密码功能的方法
Apr 15 Javascript
jquery插件Jplayer使用方法简析
Apr 22 Javascript
BootStrap下拉菜单和滚动监听插件实现代码
Sep 26 Javascript
Javascript 实现全屏滚动实例代码
Dec 31 Javascript
10个最优秀的Node.js MVC框架
Aug 24 Javascript
使用JS判断移动端手机横竖屏状态
Jul 30 Javascript
Vue export import 导入导出的多种方式与区别介绍
Feb 12 Javascript
vue微信分享插件使用方法详解
Feb 18 Javascript
解决vue动态路由异步加载import组件,加载不到module的问题
Jul 26 Javascript
Openlayers绘制聚合标注
Sep 28 Javascript
JavaScript使用类似break机制中断forEach循环的方法
Nov 13 #Javascript
小程序登录态管理的方法示例
Nov 13 #Javascript
Vuex 使用 v-model 配合 state的方法
Nov 13 #Javascript
vue代码分割的实现(codesplit)
Nov 13 #Javascript
详解vuex之store拆分即多模块状态管理(modules)篇
Nov 13 #Javascript
JS获取当前时间的实例代码(昨天、今天、明天)
Nov 13 #Javascript
checkbox在vue中的用法小结
Nov 13 #Javascript
You might like
php获取某个目录大小的代码
2008/09/10 PHP
《PHP编程最快明白》第八讲:php启发和小结
2010/11/01 PHP
PHP中几种常见的超时处理全面总结
2012/09/11 PHP
基于php-fpm的配置详解
2013/06/03 PHP
推荐一本PHP程序猿都应该拜读的书
2014/12/31 PHP
yii2框架中使用下拉菜单的自动搜索yii-widget-select2实例分析
2016/01/09 PHP
yii2 modal弹窗之ActiveForm ajax表单异步验证
2016/06/13 PHP
判断页面是关闭还是刷新的js代码
2007/01/28 Javascript
在IE 浏览器中使用 jquery的fadeIn() 效果 英文字符字体加粗
2011/06/02 Javascript
你的 mixin 真的兼容 ECMAScript 5 吗?
2013/04/11 Javascript
JS比较两个时间大小的简单示例代码
2013/12/20 Javascript
javascript每日必学之多态
2016/02/23 Javascript
JavaScript读二进制文件并用ajax传输二进制流的方法
2016/07/18 Javascript
Windows环境下npm install 报错: operation not permitted, rename的解决方法
2016/09/26 Javascript
JavaScript之iterable_动力节点Java学院整理
2017/06/29 Javascript
浅谈vuepress 踩坑记
2018/04/18 Javascript
animate.css在vue项目中的使用教程
2018/08/05 Javascript
JavaScript实现简单计算器功能
2019/12/19 Javascript
js实现橱窗展示效果
2020/01/11 Javascript
如何通过javaScript去除字符串两端的空白字符
2020/02/06 Javascript
js实现双色球效果
2020/08/02 Javascript
基于react项目打包css引用路径错误解决方案
2020/10/28 Javascript
分享给Python新手们的几道简单练习题
2017/09/21 Python
pandas数据预处理之dataframe的groupby操作方法
2018/04/13 Python
python线程中同步锁详解
2018/04/27 Python
Python迭代器模块itertools使用原理解析
2019/12/11 Python
解决ROC曲线画出来只有一个点的问题
2020/02/28 Python
python实现井字棋小游戏
2020/03/04 Python
HTML5 CSS3新的WEB标准和浏览器支持
2009/07/16 HTML / CSS
美国婴儿用品及配件购买网站:Munchkin
2019/04/03 全球购物
党校自我鉴定范文
2013/10/02 职场文书
电气工程及自动化专业自荐书范文
2013/12/18 职场文书
司法所长先进事迹
2014/06/02 职场文书
2015入党自荐书范文
2015/03/05 职场文书
Redis6.0搭建集群Redis-cluster的方法
2021/05/08 Redis
Python Pycharm虚拟下百度飞浆PaddleX安装报错问题及处理方法(亲测100%有效)
2021/05/24 Python