日常小记

js实现表单自动计算


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Document</title>
<script type="text/javascript">
function count(){
  var amount,price,money;
  amount=document.form1.txt_money2.value;
  price=document.form1.txt_date.value;
  year=document.form1.txt_year.value;
  money=year/(1+amount/100);
  money=money.toFixed(3);
  moneyy=year/(1+price/100);
  moneyy=moneyy.toFixed(3);
  moneyyy=money-moneyy;
  document.form1.txt_bail.value=money;
  document.form1.txt_baill.value=moneyy;
  document.form1.txt_bailll.value=moneyyy;
}
</script>
</head>
<body style="font-size:12px">
<table width="785" height="508" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
<td width="193" height="175">&nbsp;</td>
<td width="592" height="175">&nbsp;</td>
  </tr>
  <tr>
<td height="202">&nbsp;</td>
<td align="center" valign="middle" height="202"><table width="90%"  border="0" cellspacing="1" cellpadding="1">
  <form name="form1">
    <tr>
      <td height="22" colspan="2" align="center">加盟商信息</td>
    </tr>
    <tr>
      <td width="150" height="22" align="right">点数1:</td>
      <td height="22" align="left"><input name="txt_money" type="text" id="txt_money2" ></td>
    </tr>
    <tr>
      <td height="22" align="right">点数2:</td>
      <td height="22" align="left"><input name="txt_date" type="text" id="txt_date" ></td>
    </tr>
    <tr>
      <td height="22" align="right">金额:</td>
      <td height="22" align="left">
          <input name="txt_year" type="text" id="txt_year" size="10" onBlur="count()"> 年
      
    </tr>
    <tr>
      <td height="22" align="right">金额除以点数1:</td>
      <td height="22" align="left"><input name="txt_bail" type="text" id="txt_bail" readonly="true"></td>
    </tr>
    <tr>
      <td height="22" align="right">金额除以点数2:</td>
      <td height="22" align="left"><input name="txt_baill" type="text" id="txt_baill" readonly="true"></td>
    </tr>
    <tr>
      <td height="22" align="right">上两行相减:</td>
      <td height="22" align="left"><input name="txt_bailll" type="text" id="txt_bailll" readonly="true"></td>
    </tr>
    <tr>
      <td width="150" height="32" align="right">&nbsp;</td>
      <td height="22" align="left"><input type="submit" name="Submit3" value="  签订合同  ">
          
&nbsp;&nbsp;
    <input type="reset" name="Submit4" value="  重置内容  "></td>
    </tr>
  </form>
</table></td>
  </tr>
  <tr>
<td height="131">&nbsp;</td>
<td height="131">&nbsp;</td>
  </tr>
</table>
</body>
</html>

回复

This is just a placeholder img.