简易计算器

来源:互联网 发布:mac开发者描述文件 编辑:程序博客网 时间:2024/04/29 03:44

 <html >
<head>
<title>简易计算器</title>
<script language="javascript">
function result1(){
var num1=parseFloat(document.form1.num1.value);
var num2=parseFloat(document.form1.num2.value);
   if(document.form1.myselect.value=="+"){
    document.form1.result.value=num1+num2;
   }else if(document.form1.myselect.value=="-"){
    document.form1.result.value=num1-num2;
   } else if(document.form1.myselect.value=="*"){
    document.form1.result.value=num1*num2;
   }else if(document.form1.myselect.value=="/"){
    document.form1.result.value=num1/num2;
   }
}
</script>
</head>
<body >
<form name="form1" method="post" action="">
<table width="333" border="1" align="center">
<caption>欢迎使用简易计算器</caption>
  <tr>
    <td width="70" height="54"><input name="num1" type="text" size="15"></td>
    <td width="48"><select name="myselect">
      <option value="+" >+</option>
      <option value="-">-</option>
      <option value="*">*</option>
      <option value="/">/</option>
    </select></td>
    <td width="80"><input name="num2" type="text" size="15"></td>
    <td width="25"><label>=</label></td>
    <td width="76"><input name="result" type="text"  onFocus="result1()"size="15"></td>
  </tr>
  <tr>
    <td height="42" colspan="5" align="center"><input name="button1" type="button" value="计算" onClick="result1()"></td>
  </tr>
</table>
</form>
</body>
</html>

原创粉丝点击