<html >
<head> <title>简单计算器</title>
<style type="text/css">
div{
margin:auto;
background-color:#ff4365;
width:550px;
height:280px;
border:ridge #ff4365 4px;
}
table{
width:500px;
margin:auto;
padding-top:10px;
}
td{
height:20px;
padding:2px 6px; text-align:center;
}
input{
width:100px;
height:35px;
background:#99FFCC;
font-size:16px;
color:#0033CC;
}
.input1{
width:494px;
padding:0px;
margin:0px;
padding:5px;
font-size:25px;
background:#FFFF93;
color:#000000;
}
h1{
color:#ff4365;
font-size:50px;
border:groove 2px #ff4365;
width:160px;
background:#99FFCC;
}
</style>
<script type="text/javascript">
var num;
function buttontext(num)
{ document.getElementById('1').value+=document.getElementById(num).value;
}
function compute()
{
document.getElementById('1').value=eval(document.getElementById('1').value);
}
function del1()
{
document.getElementById('1').value=document.getElementById('1').value.substring(0,document.getElementById('1').value.length-1);
}
function del2()
{
document.getElementById('1').value='';
}
function sqrt1()
{
document.getElementById('1').value=Math.sqrt(document.getElementById('1').value);
}
function Pow()
{
document.getElementById('1').value=Math.pow(document.getElementById('1').value,2);
}
</script>
</head> <body bgcolor="#ff7575">
<center>
<h1>计算器</h1>
</center>
<div>
<table>
<tr>
<td colspan="4"><input type="text" class="input1" id="1" value="0" name="text1"/></td>
</tr> <tr>
<td><input type="button" id="2" value="+" onclick="buttontext('2')"/></td>
<td><input type="button" id="3" value="1" onclick="buttontext('3')"/></td>
<td><input type="button" id="4" value="2" onclick="buttontext('4')"/></td>
<td><input type="button" id="5" value="3" onclick="buttontext('5')"/></td>
</tr> <tr>
<td><input type="button" id="6" value="-" onclick="buttontext('6')"/></td>
<td><input type="button" id="7" value="4" onclick="buttontext('7')"/></td>
<td><input type="button" id="8" value="5" onclick="buttontext('8')"/></td>
<td><input type="button" id="9" value="6" onclick="buttontext('9')"/></td>
</tr> <tr>
<td><input type="button" id="10" value="*" onclick="buttontext('10')"/></td>
<td><input type="button" id="11" value="7" onclick="buttontext('11')"/></td>
<td><input type="button" id="12" value="8" onclick="buttontext('12')"/></td>
<td><input type="button" id="13" value="9" onclick="buttontext('13')"/></td>
</tr> <tr>
<td><input type="button" id="14" value="/" onclick="buttontext('14')"/></td>
<td><input type="button" id="15" value="0" onclick="buttontext('15')"/></td>
<td><input type="button" id="16" value="." onclick="buttontext('16')"/></td>
<td><input type="button" id="17" value="=" onclick="compute()"/></td>
</tr> <tr>
<td><input type="button" id="18" value="√" onclick="sqrt1()"/></td>
<td><input type="button" id="19" value="平方根" onclick="Pow()"/></td>
<td><input type="button" id="20" value="C" onclick="del2()"/></td>
<td><input type="button" id="21" value="←" onclick="del1()"/></td>
</tr> </table>
</div>
</body>
</html>

  

用JavaScript制作简单的计算器的更多相关文章

  1. js制作简单的计算器

    学着做了一个简单的计算器!记录记录!哈哈 <!DOCTYPE html> <html> <head> <title>简单的计算器</title&g ...

  2. JavaScript+HTML,简单的计算器实现

    成功进化到程序猿快一年多了, 还没写过计算器, 正好今天比较闲,随手写了个计算器,最简单的实现,核心是eval()方法,把字符串作为JS代码处理,把输入的信息拼接成字符串,点等号执行代码得到结果,出异 ...

  3. jQuery/javascript实现简单网页计算器

    <html> <head> <meta charset="utf-8"> <title>jQuery实现</title> ...

  4. 利用css和javascript实现简单的计算器

    <!doctype html> <html> <head> <!--声明当前页面的编码集--> <meta http-equiv="Co ...

  5. JAVASCRIPT实现简单计算器

    最终效果如下图-2,有bug:就是整数后点击%号结果正确,如果小数后面点击%的话结果就错误!其他都正常,求指点:input的value是string类型的,在JS中改如何正确处理下图-1中的if部分? ...

  6. 留念 C语言第一课简单的计算器制作

    留念 C语言第一课简单的计算器制作 学C语言这么久了.  /* 留念 C语言第一课简单的计算器制作 */   #include<stdio.h>  #include<stdlib.h ...

  7. javascript 简单的计算器

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx. ...

  8. 使用qt制作一个简单的计算器

    前言:今天使用qt制作了一个很简单的计算器,觉得挺有意思的,所以在这里跟大家分享一下. 这里先跟大家说说使用到的函数: 一.槽连接函数 connect(信号发送者,发送的信号,信号接收者,信号接收者的 ...

  9. Highcharts使用教程(1):制作简单图表

    今天我们要使用JavaScript图表Highcharts制作简单的柱形图,我们已经安装好Highcharts,让我们开始制作图表吧. 步骤一 在网页中添加一个div.设置id,设置图表长.高.代码如 ...

随机推荐

  1. 深入理解C++11

    [深入理解C++11] 1.很多 现实 的 编译器 都 支持 C99 标准 中的__ func__ 预定 义 标识符 功能, 其 基本 功能 就是 返回 所在 函数 的 名字. 编译器 会 隐式 地 ...

  2. javaMail实现收发邮件(五)

    控制台打印出的内容,我们无法阅读,其实,让我们自己来解析一封复杂的邮件是很不容易的,邮件里面格式.规范复杂得很.不过,我们所用的浏览器内置了解析各种数据类型的数据处理模块,我们只需要在把数据流传输给浏 ...

  3. ArrayList 加强版的数组

    ArrayList 泛型类. 描述:可以自动扩容的数组. 特点:插入和删除慢,查找快. 现在来创建一个 要放String的ArrayList ArrayList list = new ArrayLis ...

  4. C#使用File.Create()创建文件后资源被占用

    由于文件被占用不能读写,所以报错“另一个程序正在使用此文件进程无法访问” 解决方法是在创建文件后立即Dispose掉 File.Create(path).Dispose();

  5. PHP上传图片例子

    PHP上传图片例子  源码下载 两个文件: tu.php upload.php   tu.php 代码: <?php ini_set("display_errors", &q ...

  6. c# 通过URl 获取返回的json格式数据

    方法一 http://blog.csdn.net/angle_greensky110/article/details/52209497 protected string GetJson(string ...

  7. Spark2.0学习(二)--------RDD详解

    添加针对scala文件的编译插件 ------------------------------ <?xml version="1.0" encoding="UTF- ...

  8. Qt跨平台开发Wince5.0和Android程序

    所谓跨平台是指维护一份代码,可编译出多平台的应用程序.Qt这方面虽然已经做的不错,但性能还是体验,和原生开发工具开发的程序相比,差距还是不小的.但单从生产应用的角度来说,可以采用,不失为一种好的解决方 ...

  9. Tigase 发送消息的流程源码分析

    XMPP 的<message/>节是使用基本的”push”方法来从一个地方到另一个地方得到消息.因为消息通常是不告知的,它们是一种”fire-and-forget”(发射后自寻目的)的机制 ...

  10. github分支规范

    转自:https://www.cnblogs.com/xuld 一.目的 我们制定分支规范,意在实现以下目标: 减少沟通成本:开发者可以很清晰地知道需要修改的代码位于哪个分支. 减少 bug 隐患:避 ...