<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS网页计算器</title>
<script type="text/javascript">
var number="" ,number2,a,result=""
function input(n)
{result=""
number=number+n
document.myform.mytext.value=number
}
function myclear(n)
{result=""
number=""
number2=""
document.myform.mytext.value=number
}
function plus()
{a=1
if(result!="")
{number=result
result=""}
number2=number
number=""
}
function minus()
{a=2
if(result!="")
{number=result
result=""}
number2=number
number=""
}
function times()
{a=3
if(result!="")
{number=result
result=""}
number2=number
number=""
}
function divide()
{a=4
if(result!="")
{number=result
result=""}
number2=number
number=""
}
function point()
{
number=number+"."
}
function precent()
{
number=parseFloat(number)*0.01
document.myform.mytext.value=number
number=""
}
function reciprocal()
{
number=1/parseFloat(number)
document.myform.mytext.value=number
number=""
}
function sign()
{
number=parseFloat(number)*(-1)
document.myform.mytext.value=number
}
function backspace()
{
document.myform.mytext.value=document.myform.mytext.value.slice(0,-1)
number=document.myform.mytext.value
}
function ce(n)
{result=""
number=""
document.myform.mytext.value=number
}
function radical()
{
number=Math.sqrt(parseFloat(number))
document.myform.mytext.value=number
}
function equal()
{
if(a==1)
{result=parseFloat(number)+parseFloat(number2)
document.myform.mytext.value=result
number=""
}
if(a==2)
{result=parseFloat(number)*(-1)+parseFloat(number2)
document.myform.mytext.value=result
number=""
}
if(a==3)
{result=parseFloat(number)*parseFloat(number2)
document.myform.mytext.value=result
number=""
}
if(a==4)
{result=parseFloat(number2)*(1/parseFloat(number))
document.myform.mytext.value=result
number=""
}
}
</script>
<style type="text/css">
input {font:华文细黑; font-weight:700; color:#0033CC;}
</style>
</head>
<body background="2012052412255329.jpg">
<form name="myform">
<table border="5" style="border-color: #FFFFFF" align="center" cellpadding="0" cellspacing="0" background="2012052412255329.jpg" >
<tr align="center" valign="middle">
<th height="40" colspan="5"><input type="text" dir="rtl" style="width:300px; height:75px; font-size:20px;"" name="mytext" value="JS网页计算器" /></th>
</tr>
<tr>
<th width="64" height="69" align="center" valign="middle" ><input name="button" type="button" value="←" onclick="backspace()" style="height:40px; width:50px;" /></th>
<th width="50"><input name="button" type="button" value="CE" onclick="ce()" style="height:40px; width:50px; font:华文细黑; font-weight:700;" /></th>
<th width="54"><input name="button" type="button" value="C" onclick="myclear()" style="height:40px; width:50px;" /></th>
<th width="54"><input name="button" type="button" value="±" onclick="sign()" style="height:40px; width:50px;" /></th>
<th width="50"><input name="button" type="button" value="√" onclick="radical()" style="height:40px; width:50px;" /></th>
</tr>
<tr >
<th width="64" height="60" align="center" valign="middle">
<input name="button" type="button" value="1" onclick="input(value)"style="height:40px; width:50px;" /></th>
<th><input name="button" type="button" value="2" onclick="input(value)" style="height:40px; width:50px;" /></th>
<th><input name="button" type="button" value="3" onclick="input(value)"style="height:40px; width:50px;" /></th>
<th ><input name="button" type="button" value="/" onclick="divide()" style="height:40px; width:50px;" /></th>
<th><input name="button" type="button" value="%" onclick="precent()" style="height:40px; width:50px;" /></th>
</tr>
<tr>
<th width="64" height="62" align="center" valign="middle"><input name="button" type="button" value="4" onclick="input(value)" style="height:40px; width:50px;"/></th>
<th><input name="button" type="button" value="5" onclick="input(value)" style="height:40px; width:50px;" /></th>
<th><input name="button" type="button" value="6"onclick="input(value)" style="height:40px; width:50px;" /></th>
<th "><input name="button" type="button" value="×" onclick="times()" style="height:40px; width:50px;" /></th>
<th><input name="button" type="button" value="1/x" onclick="reciprocal()" style="height:40px; width:50px;" /></th>
</tr>
<tr>
<th width="64" height="59" align="center" valign="middle">
<input name="button" style="height:40px; width:50px;" type="button" value="7" onclick="input(value)" /></th>
<th><input name="button" type="button" value="8" onclick="input(value)" style="height:40px; width:50px;" /></th>
<th><input name="button" type="button" value="9" onclick="input(value)" style="height:40px; width:50px;" /></th>
<th ><input name="button" type="button" value="-" onclick="minus()" style="height:40px; width:50px;" /></th>
<th rowspan="2"><input name="button" type="button" value="=" onclick="equal()" style="height:120px; width:50px;" /></th>
</tr>
<tr>
<th height="40" colspan="2" align="center" valign="middle"><input name="button" type="button" value="0"onclick="input(value)" style="height:40px; width:120px;" /></th>
<th><input name="button" type="button" value="." onclick="point()" style="height:40px; width:50px;" /></th>
<th ><input name="button" type="button" value="+" onclick="plus()" style="height:40px; width:50px;" /></th>
</tr>
</table>
</form>
</body>
</html>
自己编的第一个JS网页计算器
5星 · 超过95%的资源 需积分: 6 121 浏览量
2014-04-19
21:59:23
上传
评论 1
收藏 64KB RAR 举报
nceuaprsf
- 粉丝: 45
- 资源: 2
最新资源
- AIS2024 valid
- 最入门的爬虫代码 python.docx
- 爬虫零基础入门-爬取天气预报.pdf
- 最通俗易懂的 MongoDB 非结构化文档存储数据库教程.zip
- 以mongodb为数据库的订单物流小项目.zip
- 腾讯云-mongodb数据库, 项目部署.zip
- 腾讯 APIJSON 的 MongoDB 数据库插件.zip
- 理解非关系型数据库和关系型数据库的区别.zip
- 操作简单的Mongodb网页web管理工具,基于Spring Boot2.0支持mongodb集群.zip
- tms-mongodb-web,提供访问mongodb数据的REST API和可灵活扩展的mongodb web 客户端.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈