js 做计算器

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="calc.aspx.cs" Inherits="calc" %>

<!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 runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 22%;
}
#Button1
{
height: 41px;
width: 60px;
}
#Button2
{
height: 41px;
width: 60px;
}
#Button3
{
height: 41px;
width: 63px;
}
#Button4
{
height: 41px;
width: 64px;
}
#Button5
{
height: 41px;
width: 57px;
}
#Button6
{
height: 41px;
width: 61px;
}
#Button7
{
height: 41px;
width: 64px;
}
#Button8
{
height: 41px;
width: 64px;
}
#Button9
{
height: 41px;
width: 62px;
}
#Button10
{
height: 41px;
width: 63px;
}
#Button11
{
height: 41px;
width: 67px;
}
#Button12
{
height: 41px;
width: 64px;
}
#Button13
{
height: 41px;
width: 61px;
}
#Button14
{
height: 41px;
width: 59px;
}
#Button15
{
height: 41px;
width: 67px;
}
#Button16
{
height: 41px;
width: 65px;
}
#Text1
{
width: 258px;
height: 38px;
}
.style2
{
width: 62px;
}
#Button17
{
height: 41px;
width: 61px;
}
#Button18
{
height: 41px;
width: 63px;
}
#Button19
{
height: 41px;
width: 67px;
}
#Button20
{
height: 41px;
width: 62px;
}
</style>
<script language="javascript" type="text/javascript">
var num;
function btntext(num) {
document.getElementById('Text1').value += document.getElementById(num).value;
}//给文本框赋值
function ev() {
document.getElementById('Text1').value = eval(document.getElementById('Text1').value);
} //计算文本框内的表达式
function clear() {
document.getElementById('Text1').value =0;
} //吧文本框内的内容清0
function SQRT() {
var disp = document.getElementById('Text1');
disp.value = Math.sqrt(disp.value);

}//开根号

function Pow() {
var disp = document.getElementById('Text1');
disp.value = Math.pow(disp.value, 2);
}//平方
function del() {
var disp = document.getElementById('Text1');
disp.value = disp.value.substring(0, disp.value.length - 1)
} //删除
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table align="center" class="style1"
style="background-color: #C0C0C0; height: 291px;">
<tr>
<td colspan="4" style="background-color: #00FFFF; text-align: center;">
<input id="Text1" type="text" /></td>
</tr>
<tr>
<td style="background-color: #00FFFF">
<input id="+" type="button" value="+" οnclick="btntext('+')"/></td>
<td style="background-color: #00FFFF">
<input id="1" type="button" value="1" name='1' οnclick="btntext('1')" /></td>
<td style="background-color: #00FFFF">
<input id="2" type="button" value="2" οnclick="btntext('2')"/></td>
<td class="style2" style="background-color: #00FFFF">
<input id="3" type="button" value="3" οnclick="btntext('3')"/></td>
</tr>
<tr>
<td style="background-color: #00FFFF">
<input id="-" type="button" value="-" οnclick="btntext('-')"/></td>
<td style="background-color: #00FFFF">
<input id="4" type="button" value="4" οnclick="btntext('4')"/></td>
<td style="background-color: #00FFFF">
<input id="5" type="button" value="5" οnclick="btntext('5')"/></td>
<td class="style2" style="background-color: #00FFFF">
<input id="6" type="button" value="6" οnclick="btntext('6')"/></td>
</tr>
<tr>
<td style="background-color: #00FFFF">
<input id="*" type="button" value="*" οnclick="btntext('*')"/></td>
<td style="background-color: #00FFFF">
<input id="7" type="button" value="7" οnclick="btntext('7')"/></td>
<td style="background-color: #00FFFF">
<input id="8" type="button" value="8" οnclick="btntext('8')"/></td>
<td class="style2" style="background-color: #00FFFF">
<input id="9" type="button" value="9" οnclick="btntext('9')"/></td>
</tr>
<tr>
<td style="background-color: #00FFFF">
<input id="/" type="button" value="/" οnclick="btntext('/')"/></td>
<td style="background-color: #00FFFF">
<input id="0" type="button" value="0" οnclick="btntext('0')"/></td>
<td style="background-color: #00FFFF">
<input id="." type="button" value="." style="font-weight: bold" οnclick="btntext('.')"/></td>
<td class="style2" style="background-color: #00FFFF">
<input id="Button16" type="button" value="=" οnclick="ev()"/></td>
</tr>
<tr>
<td style="background-color: #00FFFF">
<input id='根号' type="button" value="√" οnclick="SQRT()"/></td>
<td style="background-color: #00FFFF">
<input id="平方" type="button" value="²" οnclick="Pow()"/></td>
<td style="background-color: #00FFFF">
<input id="Button19" type="button" value="C" οnclick="clear()"/></td>
<td class="style2" style="background-color: #00FFFF">
<input id="Button20" type="button" value="←" οnclick="del()"/></td>
</tr>
</table>
</div>
</form>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值