JAVASCRIPT计算器

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>计算器</title>
<style type="text/css"></style>
</head>

 

</head>

<body>
 
<form action name="Calculator" class="font">
<center><table bgcolor="#aaaaaa" border="1" cellpadding="2" bordercolorlight="#808080" bordercolordark="#FFFFFF" class="font"></center>
<tr>
<td  bgcolor="#000080" colspan="5" align="center" ><input name="t1" size="22" value="0" width="100%" class="font"></td>
</tr>
<tr>


 <td><input type="button" value=" POWER " name="power" οnclick="powerclick()"></td>
 <td><input type="button" value=" Clear " name="clear" οnclick="clearclick()"></td>
 <td><input type="button" value=" Back " name="back" οnclick="backclick()"></td>
 </tr>
  
 <tr><td><input type="button" value="  1  " name="B1" οnclick="numclick(this)"></td>
 <td><input type="button" value="  2  " name="B2" οnclick="numclick(this)"></td>
 <td><input type="button" value="  3  " name="B3" οnclick="numclick(this)"></td>
 <td><input type="button" value="  4  " name="B4" οnclick="numclick(this)"></td>
 </tr>
 <tr>
 <td><input type="button" value="  5  " name="B5" οnclick="numclick(this)"></td>
 <td><input type="button" value="  6  " name="B6" οnclick="numclick(this)"></td>
 <td><input type="button" value="  7  " name="B7" οnclick="numclick(this)"></td>
 <td><input type="button" value="  8  " name="B8" οnclick="numclick(this)"></td>
 </tr>
 <tr>
 <td><input type="button" value="  9  " name="B9" οnclick="numclick(this)"></td>
 <td><input type="button" value="  0  " name="B0" οnclick="numclick(this)"></td>
 <td><input type="button" value="  .  " name="B11" οnclick="numclick(this)"></td>
 <td><input type="button" value="  =  " name="BE" οnclick="equalclick()"></td>
 </tr>
 <p align="center">
 <td><input type="button" value="  +  " name="BP" οnclick="symbolclick(this)"></td>
 <td><input type="button" value="  -  " name="BJ" οnclick="symbolclick(this)"></td>
 <td><input type="button" value="  *  " name="BM" οnclick="symbolclick(this)"></td>
 <td><input type="button" value="  /  " name="BD" οnclick="symbolclick(this)"></td>
</tr>
</form>
<script>
<!--
 var flag=0
 var add1
 var s1
 function numclick(b)
 {
  if (flag==0)
  { 
   document.forms[0].t1.value=""
   flag=1
  }
  document.forms[0].t1.value=document.forms[0].t1.value+b.value.substring(2,3)
 }
 function symbolclick(b)
 {
  switch (s1)
  {
   case '*':
    document.forms[0].t1.value=String(Number(document.forms[0].t1.value)*add1)
    break
   case '/':
    document.forms[0].t1.value=String(add1/Number(document.forms[0].t1.value))
    break
   case '+':
    document.forms[0].t1.value=String(add1+Number(document.forms[0].t1.value))
    break
   case '-':
    document.forms[0].t1.value=String(add1-Number(document.forms[0].t1.value))
    break
  }
   add1=Number(document.forms[0].t1.value)
   s1=b.value.substring(2,3)
   flag=0
 }
 function equalclick()
 {
  switch (s1)
  {
   case '*':
    document.forms[0].t1.value=String(Number(document.forms[0].t1.value)*add1)
    break
   case '/':
    document.forms[0].t1.value=String(add1/Number(document.forms[0].t1.value))
    break
   case '+':
    document.forms[0].t1.value=String(add1+Number(document.forms[0].t1.value))
    break
   case '-':
    document.forms[0].t1.value=String(add1-Number(document.forms[0].t1.value))
    break
  }
  flag=0
  s1=''
 }
 function clearclick()
 {
  document.forms[0].t1.value='0.'
  add1=0
  s1=''
  flag=0
 }
 function backclick()
 {
  if (document.forms[0].t1.value.length==1)
  {
   document.forms[0].t1.value="0."
   flag=0
  }
  else
   document.forms[0].t1.value=document.forms[0].t1.value.substring(0,document.forms[0].t1.value.length-1)
 }
 function powerclick()
 {
  document.forms[0].t1.value=String(Number(document.forms[0].t1.value)*Number(document.forms[0].t1.value))
  add1=Number(document.forms[0].t1.value)  
 }


-->
</script>

</body>

</html> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值