js制作简单的计算器
学着做了一个简单的计算器!记录记录!哈哈
<!DOCTYPE html>
<html>
<head>
<title>简单的计算器</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
input{width:100%}
</style>
</head>
<body>
<script type="text/javascript">
function compute(obj)
{
obj.expr.value=eval(obj.expr.value)
}
var plus="+";
var minus="-";
var multiply="*";
var divide="/";
var decimal=".";
function enter(obj,string)
{
obj.expr.value+=string;
}
function cle(obj)
{
obj.expr.value='';
}
</script>
<form >
<table border=1>
<tr >
<td colspan="4"><input type="text" name="expr" size="30" style="width:97%"></td>
</tr>
<tr>
<td><input type="button" value="7" onclick="enter(this.form,7)"></td>
<td><input type="button" value="8" onclick="enter(this.form,8)"></td>
<td><input type="button" value="9" onclick="enter(this.form,9)"></td>
<td><input type="button" value="/" onclick="enter(this.form,divide)"></td>
</tr>
<tr>
<td><input type="button" value="4" onclick="enter(this.form,4)"></td>
<td><input type="button" value="5" onclick="enter(this.form,5)"></td>
<td><input type="button" value="6" onclick="enter(this.form,6)"></td>
<td><input type="button" value="*" onclick="enter(this.form,multiply)"</td>
</tr>
<tr>
<td><input type="button" value="1" onclick="enter(this.form,1)"></td>
<td><input type="button" value="2" onclick="enter(this.form,2)"></td>
<td><input type="button" value="3" onclick="enter(this.form,3)"></td>
<td><input type="button" value="-" onclick="enter(this.form,minus)"></td>
</tr>
<tr>
<td colspan="2"><input type="button" value="0" onclick="enter(this.form,0)"></td>
<td><input type="button" value="." onclick="enter(this.form,decimal)"></td>
<td><input type="button" value="+" onclick="enter(this.form,plus)"></td>
</tr>
<tr>
<td colspan="2" ><input type="button" value="=" onclick="compute(this.form)" ></td>
<td colspan="2"><input type="button" value="AC" size=3 onclick="cle(this.form)"></td>
</tr>
</table>
</form>
</body>
</html>
js制作简单的计算器的更多相关文章
- JS——制作简单的网页计算器
用JS做了一个简易的网页计算器 <!DOCTYPE html> <html lang="en"> <head> <meta charset ...
- 用JavaScript制作简单的计算器
<html > <head> <title>简单计算器</title> <style type="text/css"> ...
- 【前端】Vue.js实现简单价格计算器
价格计算器 实现效果: 实现代码及注释: <!DOCTYPE html> <html> <head> <title>价格计算器</title> ...
- d3.js 制作简单的俄罗斯方块
d3.js是一个不错的可视化框架,同时对于操作dom也是十分方便的.今天我们使用d3.js配合es6的类来制作一个童年小游戏--俄罗斯方块.话不多说先上图片. 1. js tetris类 由于方法拆分 ...
- d3.js 制作简单的贪吃蛇
d3.js是一个不错的可视化框架,同时对于操作dom也是十分方便的.今天我们使用d3.js配合es6的类来制作一个童年小游戏–贪吃蛇.话不多说先上图片. 1. js snaker类 class Sna ...
- 利用css+原生js制作简易钟表
利用css+原生js制作简单的钟表.效果如下所示 实现该效果,分三大块:html.javascript.css html部分html部分比较简单,定义一个clock的div,内部有原点.时分秒针.日期 ...
- JS制作图片切换
<!DOCTYPE html> <html> <head> <title>纯JS制作简单的图片切换</title> <meta cha ...
- 留念 C语言第一课简单的计算器制作
留念 C语言第一课简单的计算器制作 学C语言这么久了. /* 留念 C语言第一课简单的计算器制作 */ #include<stdio.h> #include<stdlib.h ...
- JS实现一个简单的计算器
使用JS完成一个简单的计算器功能.实现2个输入框中输入整数后,点击第三个输入框能给出2个整数的加减乘除.效果如上: 第一步: 创建构建运算函数count(). 第二步: 获取两个输入框中的值和获取选择 ...
随机推荐
- regeneratorRuntime未定义
babel-preset-stage-2 { "presets": ["es2015", "stage-2"], "plugins ...
- wampserver 2.5多站点配置
wampserver2.5版本与之前老版本配置有区别,假设wamp安装在d:/wamp下.第一步:修改D:/wamp/bin/apache/apache2.4.9/conf/httpd.conf 文件 ...
- Vuejs——(2)Vue生命周期,数据,手动挂载,指令,过滤器
(八)传入的数据绑定 先创建一个对象(假如是obj),然后将他传入Vue实例中,作为data属性的值,那么 ①obj的值的变化,将影响Vue实例中的值的变化: ②相反一样: ③可以在Vue实例外面操纵 ...
- 结合Apache和Tomcat实现集群和负载均衡 JK 方式 2 (转)
本文Apache+Tomcat集群配置 基于最新的Apache和Tomcat,具体是2011年4月20日最新的Tomcat和Apache集群和负载均衡配置. 准备环境 Apache Apa ...
- LeetCode:461. Hamming Distance
package BitManipulation; //Question 461. Hamming Distance /* The Hamming distance between two intege ...
- 分析恶意windows程序
1.windows 注册表 注册表根键 注册表被划分为下面5个根键 HKEY_LOCAL_MACHINE(HKLM) 保存对本地机器全局设置 HKEY_CURRENT_USER(HKCU) 保存当前用 ...
- 瘋耔java语言笔记
一◐ java概述 1.1 ...
- Python Locust对指定网站“一键压测”
[本文出自天外归云的博客园] 前篇 前篇:Python Locust性能测试框架实践 本篇 承上——归纳过程 在前篇的基础上,我们可以利用Locust性能测试框架编写python脚本对指定网站或者接口 ...
- Fisher–Yates shuffle 洗牌(shuffle)算法
今天在敲undersore的源码,数组里面有一个shuffle,把数组随机打乱. _.shuffle = function(obj) { var set = isArrayLike(obj) ? ob ...
- 【线段树区间合并】HDU1540-Tunnel Warfare
一.题目 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...