javascript+css创建的在线计算器

所属分类: 网页特效-实用工具    2024-12-02 08:39:38

javascript+css创建的在线计算器 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

javascript+css创建的在线计算器(共3个文件)

    • script.js
    • index.html
    • style.css

使用方法

const display = document.querySelector(".display");
const buttons = document.querySelectorAll("button");
const specialChars = ["%", "*", "/", "-", "+", "="];
let output = "";

//Define function to calculate based on button clicked.
const calculate = (btnValue) => {
  display.focus();
  if (btnValue === "=" && output !== "") {
    //If output has '%', replace with '/100' before evaluating.
    output = eval(output.replace("%", "/100"));
  } else if (btnValue === "AC") {
    output = "";
  } else if (btnValue === "DEL") {
    //If DEL button is clicked, remove the last character from the output.
    output = output.toString().slice(0, -1);
  } else {
    //If output is empty and button is specialChars then return
    if (output === "" && specialChars.includes(btnValue)) return;
    output += btnValue;
  }
  display.value = output;
};

//Add event listener to buttons, call calculate() on click.
buttons.forEach((button) => {
  //Button click listener calls calculate() with dataset value as argument.
  button.addEventListener("click", (e) => calculate(e.target.dataset.value));
});

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 实用工具

基于javascript在线图片裁剪实用工具

提供了4根平行线,通过拖拽移动来获取图片截取区域,还可自定义定位裁剪区域,从而实现图像选择,还带了裁剪实时图片预览。
  实用工具
 21018  0

jquery针对DIV任意元素鼠标悬停显示文字提示插件

一款鼠标悬停元素上显示文字工具提示特效,只需要在DIV元素中添加自定义标签title即可。
  实用工具
 8727  0

jquery+css实现的环形文字盖章展示特效

一款模拟印章环形文字特效,支持在线自定义文字及角度调整。
  实用工具
 6864  0

jquery纯数字多语言转换器插件

一个多语言数字到单词转换器,可将阿拉伯数字自定义转换为指定语言的单词书写,非常实用。
  实用工具
 3970  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论