利息计算器
<!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=utf-8" />
<title>利息计算器</title>
<script language="javascript">
<!--begin hiding of script
var riqi;
var money;
var x;
var y;
var z;
var s;
var sd;
var xx;
var yy;
var lx;
function makeArray(n) { //定义数组对象makeArray
for (var i = 1; i <= n; i++) {
this[i] = 0;
this.length = n;
}
return this;
}
function chktxtbj() {
tbj = document.data.elements[10].name;
if (document.data.elements[10].value == "") { //判'本金'文本框输入是否为空
alert("请输入本金额。");
document.data.elements[10].focus();
return false;
}
if (document.data.elements[10].value.length < 2) { //判'本金'文本框输入字符串长度是否小于2
alert("输入金额最少不低于两位。");
document.data.elements[10].focus();
return false;
}
if (document.data.elements[10].value.length > 10) { //判'本金'文本框输入字符串长度是否大于10
alert("输入金额最多不超过10位。");
document.data.elements[10].focus();
return false;
}
var checkOK = "0123456789-.";
var checkStr = document.data.elements[10].value;
var allValid = true;
var decPoints = 0;
var allNum = "";
for (i = 0; i < checkStr.length; i++) {
ch = checkStr.charAt(i); //检查输入字符串是否含有除'0123456789.'以外的字符
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j)) {
break;
}
if (j == checkOK.length) {
allValid = false;
break;
}
if (ch == ".") { //把输入字符串逐字符存入allNum中
allNum += ".";
decPoints++; //50
} else {
allNum += ch;
}
}
if (!allValid) { //如果输入字符串含有非数值字符,则给出警告
alert("请输入数值!");
document.data.elements[10].focus();
return false;
}
if (decPoints > 1) { //如果字符串含有一个以上的".",则提示输入无效
alert("请输入有效数值!");
document.data.elements[10].focus();
return false;
}
var chkVal = allNum;
var prsVal = parseFloat(allNum);
if (chkVal != "" && !(prsVal >= "10")) { //提示输入>=10的数值
alert("输入数值必须大于或等于10。");
document.data.elements[10].focus();
return false;
}
x = cz(xx);
if (x == 3 && document.data.elements[10].value < 5000) {
alert("存本取息要求5000元起存。");
document.data.elements[10].focus;
return false;
}
if (x == 1 && document.data.elements[10].value < 50) {
alert("整存整取要求50元起存。");
document.data.elements[10].focus;
return false;
}
if (x == 2 && document.data.elements[10].value < 5) {
alert("零存整取要求5元起存。");
document.data.elements[10].focus;
return false;
}
}
function chkdate() {
tdat = document.data.elements[9].name;
if (document.data.elements[9].value.length < 8) {
alert("请输入标准日期格式!");
document.data.elements[9].focus;
return false;
}
var datchk = "0123456789"
var datbool = true
var datch = document.data.elements[9].value
for (i = 0; i < datch.length; i++) { //140
ch = datch.charAt(i); //检查输入字符串是否含有除'0123456789'以外的字符
for (j = 0; j < datchk.length; j++)
if (ch == datchk.charAt(j)) {
break;
}
if (j == datchk.length) {
datbool = false;
break;
}
}
if (!datbool) {
alert("输入日期无效!");
document.data.elements[9].focus;
return false;
}
month = datch.substring(4, 6);
day = datch.substring(6, 8);
if (month > 12 || day > 31) {
alert("输入日期无效!");
document.data.elements[9].focus;
return false;
}
if (datch < 19930515) {
alert("存款日期必须在1993年5月15日以后");
document.data.elements[9].focus;
return false;
}
}
function chkcq() {
x = cz(xx);
y = cq(yy);
if (x == 2 || x == 3)
if (y == 3 || y == 6 || y == 24) {
alert("零存整取/存本取息的存期只有一年、三年和五年");
document.data.elements[5].click();
return false;
}
}
function cz(xx) {
for (i = 0; i <= 2; i++) //获取储种所选项的值于x
if (document.data.elements[i].checked)
xx = document.data.elements[i].value
return xx;
}
function cq(yy) {
for (j = 3; j <= 8; j++) //获取存期所选项的值于y
if (document.data.elements[j].checked)
yy = document.data.elements[j].value
return yy;
}
function lilv(z) {
lilv1 = new makeArray(6); // 99,6,10,后的利率表
lilv1[1] = 0.0198;
lilv1[2] = 0.0216;
lilv1[3] = 0.0225;
lilv1[4] = 0.0243;
lilv1[5] = 0.0270;
lilv1[6] = 0.0288;
lilv2 = new makeArray(6); // 98,12,7,
lilv2[1] = 0.0279;
lilv2[2] = 0.0333;
lilv2[3] = 0.0378;
lilv2[4] = 0.0396;
lilv2[5] = 0.0414;
lilv2[6] = 0.0450;
lilv3 = new makeArray(6); //98,7,1,
lilv3[1] = 0.0279;
lilv3[2] = 0.0396;
lilv3[3] = 0.0477; //100
lilv3[4] = 0.0486;
lilv3[5] = 0.0495;
lilv3[6] = 0.0522;
lilv4 = new makeArray(6); //98,3,25,
lilv4[1] = 0.0288;
lilv4[2] = 0.0414;
lilv4[3] = 0.0522;
lilv4[4] = 0.0558;
lilv4[5] = 0.0621;
lilv4[6] = 0.0666;
lilv5 = new makeArray(6); //97,10,23,
lilv5[1] = 0.0288;
lilv5[2] = 0.0414;
lilv5[3] = 0.0567;
lilv5[4] = 0.0594;
lilv5[5] = 0.0621;
lilv5[6] = 0.0666;
lilv6 = new makeArray(6); //96,8,23,
lilv6[1] = 0.0333;
lilv6[2] = 0.0540;
lilv6[3] = 0.0747;
lilv6[4] = 0.0792;
lilv6[5] = 0.0828;
lilv6[6] = 0.0900;
lilv7 = new makeArray(6); //96,5,1,
lilv7[1] = 0.0486;
lilv7[2] = 0.0720;
lilv7[3] = 0.0918;
lilv7[4] = 0.0990;
lilv7[5] = 0.1080;
lilv7[6] = 0.1206;
lilv8 = new makeArray(6); //93,7,11,
lilv8[1] = 0.0666;
lilv8[2] = 0.0900;
lilv8[3] = 0.1098;
lilv8[4] = 0.1170;
lilv8[5] = 0.1224;
lilv8[6] = 0.1386;
lilv9 = new makeArray(6); //93,5,15,
lilv9[1] = 0.0486;
lilv9[2] = 0.0720;
lilv9[3] = 0.0918;
lilv9[4] = 0.0990;
lilv9[5] = 0.1080;
lilv9[6] = 0.1206;
x = cz(xx);
y = cq(yy);
riqi = document.data.elements[9].value;
//chkdate();
money = document.data.elements[10].value;
//chktxtbj();
//chkcq();
var l = 0;
if (riqi >= 19990610) { //判用户存款日期是否在99年6月10日以后
if (x == 1) { //判用户所选储种
if (y == 3) z = lilv1[1] //根据用户所选存期获取相应利率
else if (y == 6) z = lilv1[2]
else if (y == 12) z = lilv1[3]
else if (y == 24) z = lilv1[4]
else if (y == 36) z = lilv1[5]
else if (y == 60) z = lilv1[6]
} else if (x == 2) {
if (y == 12) z = lilv1[1]
else if (y == 36) z = lilv1[2]
else if (y == 60) z = lilv1[3]
} else if (x == 3) {
if (y == 12) z = lilv1[1]
else if (y == 36) z = lilv1[2]
else if (y == 60) z = lilv1[3]
} else if (x == 4) {
if (y < 6) z = lilv1[1]
else if (y < 12) z = lilv1[2]
else z = lilv1[3]
}
} else if (riqi >= 19981207) {
if (x == 1) {
if (y == 3) z = lilv2[1]
else if (y == 6) z = lilv2[2]
else if (y == 12) z = lilv2[3]
else if (y == 24) z = lilv2[4]
else if (y == 36) z = lilv2[5]
else if (y == 60) z = lilv2[6]
} else if (x == 2) {
if (y == 12) z = lilv2[2]
else if (y == 36) z = lilv2[3]
else if (y == 60) z = lilv2[5]
} else if (x == 3) {
if (y == 12) z = lilv2[2]
else if (y == 36) z = lilv2[3]
else if (y == 60) z = lilv2[5]
} else if (x == 4) {
if (y < 6) z = lilv2[1]
else if (y < 12) z = lilv2[2]
else z = lilv2[3]
}
} else if (riqi >= 19980701) {
if (x == 1) {
if (y == 3) z = lilv3[1]
else if (y == 6) z = lilv3[2]
else if (y == 12) z = lilv3[3]
else if (y == 24) z = lilv3[4]
else if (y == 36) z = lilv3[5]
else if (y == 60) z = lilv3[6]
} else if (x == 2) {
if (y == 12) z = lilv3[2]
else if (y == 36) z = lilv3[3]
else if (y == 60) z = lilv3[5]
} else if (x == 3) {
if (y == 12) z = lilv3[2]
else if (y == 36) z = lilv3[3]
else if (y == 60) z = lilv3[5]
} else if (x == 4) {
if (y < 6) z = lilv3[1]
else if (y < 12) z = lilv3[2]
else z = lilv3[3]
}
} else if (riqi >= 19980325) {
if (x == 1) {
if (y == 3) z = lilv4[1]
else if (y == 6) z = lilv4[2]
else if (y == 12) z = lilv4[3]
else if (y == 24) z = lilv4[4]
else if (y == 36) z = lilv4[5]
else if (y == 60) z = lilv4[6]
} else if (x == 2) {
if (y == 12) z = lilv4[2]
else if (y == 36) z = lilv4[3]
else if (y == 60) z = lilv4[5]
} else if (x == 3) {
if (y == 12) z = lilv4[2]
else if (y == 36) z = lilv4[3]
else if (y == 60) z = lilv4[5]
} else if (x == 4) {
if (y < 6) z = lilv4[1]
else if (y < 12) z = lilv4[2]
else z = lilv4[3]
}
} else if (riqi >= 19971023) {
if (x == 1) {
if (y == 3) z = lilv5[1]
else if (y == 6) z = lilv5[2]
else if (y == 12) z = lilv5[3]
else if (y == 24) z = lilv5[4]
else if (y == 36) z = lilv5[5]
else if (y == 60) z = lilv5[6]
} else if (x == 2) {
if (y == 12) z = lilv5[2]
else if (y == 36) z = lilv5[3]
else if (y == 60) z = lilv5[5]
} else if (x == 3) {
if (y == 12) z = lilv5[2]
else if (y == 36) z = lilv5[3]
else if (y == 60) z = lilv5[5]
} else if (x == 4) {
if (y < 6) z = lilv5[1]
else if (y < 12) z = lilv5[2]
else z = lilv5[3]
}
} else if (riqi >= 19960823) {
if (x == 1) {
if (y == 3) z = lilv6[1]
else if (y == 6) z = lilv6[2]
else if (y == 12) z = lilv6[3]
else if (y == 24) z = lilv6[4]
else if (y == 36) z = lilv6[5]
else if (y == 60) z = lilv6[6]
} else if (x == 2) {
if (y == 12) z = lilv6[2]
else if (y == 36) z = lilv6[3]
else if (y == 60) z = lilv6[5]
} else if (x == 3) {
if (y == 12) z = lilv6[2]
else if (y == 36) z = lilv6[3]
else if (y == 60) z = lilv6[5]
} else if (x == 4) {
if (y < 6) z = lilv6[1]
else if (y < 12) z = lilv6[2]
else z = lilv6[3]
}
} else if (riqi >= 19960501) {
if (x == 1) {
if (y == 3) z = lilv7[1]
else if (y == 6) z = lilv7[2]
else if (y == 12) z = lilv7[3]
else if (y == 24) z = lilv7[4]
else if (y == 36) z = lilv7[5]
else if (y == 60) z = lilv7[6]
} else if (x == 2) {
if (y == 12) z = lilv7[2]
else if (y == 36) z = lilv7[3]
else if (y == 60) z = lilv7[5]
} else if (x == 3) {
if (y == 12) z = lilv7[2]
else if (y == 36) z = lilv7[3]
else if (y == 60) z = lilv7[5]
} else if (x == 4) {
if (y < 6) z = lilv7[1]
else if (y < 12) z = lilv7[2]
else z = lilv7[3]
}
} else if (riqi >= 19930711) {
if (x == 1) {
if (y == 3) z = lilv8[1]
else if (y == 6) z = lilv8[2]
else if (y == 12) z = lilv8[3]
else if (y == 24) z = lilv8[4]
else if (y == 36) z = lilv8[5]
else if (y == 60) z = lilv8[6]
} else if (x == 2) {
if (y == 12) z = lilv8[2]
else if (y == 36) z = lilv8[3]
else if (y == 60) z = lilv8[5]
} else if (x == 3) {
if (y == 12) z = lilv8[2]
else if (y == 36) z = lilv8[3]
else if (y == 60) z = lilv8[5]
} else if (x == 4) {
if (y < 6) z = lilv8[1]
else if (y < 12) z = lilv8[2]
else z = lilv8[3]
}
} else if (riqi >= 19930515) {
if (x == 1) {
if (y == 3) z = lilv9[1]
else if (y == 6) z = lilv9[2]
else if (y == 12) z = lilv9[3]
else if (y == 24) z = lilv9[4]
else if (y == 36) z = lilv9[5]
else if (y == 60) z = lilv9[6]
} else if (x == 2) {
if (y == 12) z = lilv9[2]
else if (y == 36) z = lilv9[3]
else if (y == 60) z = lilv9[5]
} else if (x == 3) {
if (y == 12) z = lilv9[2]
else if (y == 36) z = lilv9[3]
else if (y == 60) z = lilv9[5]
} else if (x == 4) {
if (y < 6) z = lilv9[1]
else if (y < 12) z = lilv9[2]
else z = lilv9[3]
}
}
return z;
}
function lixi(lx) {
x = cz(xx);
y = cq(yy);
zz = lilv(z);
var l;
if (x == 2) {
var js = parseFloat(y) + 1;
l = money * js / 2 * y * zz / 12;
} else l = money * y * zz / 12
//if (isNaN(l)) alert("输入数据无效!");
var ll = l + "0"
var lx
var lx1
var index = 0 //把计算结果保留到小数点后两位 500
var i
var c
for (i = 0; i < ll.length; i++) {
c = ll.charAt(i);
if (c == ".") index = i;
}
//index=ll.indexOf(".");
if (index == 0) lx = l
else {
lx = ll.substring(0, index + 3);
letter = ll.charAt(index + 3);
if (letter >= 5) {
lx1 = parseFloat(lx) + 0.01;
lx1 = lx1 + "0";
lx = lx1.substring(0, index + 3);
}
}
return lx;
}
function chuzhong(s) {
x = cz(xx);
if (x == 1) s = "整存整取"
else if (x == 2) s = "零存整取"
else if (x == 3) s = "存本取息"
return s;
}
function cunqi(sd) {
y = cq(yy);
if (y == 3) sd = "三个月"
else if (y == 6) sd = "六个月"
else if (y == 12) sd = "一年"
else if (y == 24) sd = "二年"
else if (y == 36) sd = "三年"
else if (y == 60) sd = "五年"
return sd;
}
function result() {
var x = cz(xx);
y = cq(yy);
var ss = chuzhong(s);
var sdsd = cunqi(sd);
var riqi = document.data.elements[9].value;
var money = document.data.elements[10].value;
var lxlx = lixi(lx);
var zz = lilv(z);
if (ss == '零存整取') {
if (sdsd == '一年') money = money * 12;
if (sdsd == '三年') money = money * 36;
if (sdsd == '五年') money = money * 60;
}
alert(" 利息计算结果" + "\n" + "\n" + "储 种 " + ss + " \n" + "\n" + "存 期 " + sdsd + "\n" + "\n" + "存款日期 " + riqi + "\n" + "\n" + "存入本金 " + money + "元\n" + "\n" + "利息总额 " + lxlx + "元\n" + "\n" + "年 利 率 " + zz * 100 + "%");
}
//-->
</script>
<title>利息计算器 </title>
</head>
<body bgcolor="#FFFFFF" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<br>
<form name="data">
<table border="1" width="366" cellpadding="4" cellspacing="0" bordercolor="#bbddff"
style="font-family: 宋体; font-size: 9pt" align="center">
<tr>
<td width="356"><div align="center"><center><p><font color="#FF0000"><span
style="font-family: 宋体; font-size: 11pt">利息计算器 </span></font></center></div></td>
</tr>
<tr align="center">
<td width="356"><span style="font-family: 宋体; font-size: 11pt">储蓄种类</span><br>
<input type="radio" value="1" checked name="chuzhong"> 整存整取
<input type="radio" name="chuzhong" value="2"> 零存整取 <input
type="radio" name="chuzhong" value="3"> 存本取息 </td>
</tr>
<tr align="center">
<td width="356"><span style="font-family: 宋体; font-size: 11pt">存款期限</span><br>
<input type="radio" value="3" name="cunqi" onClick="return chkcq()"> 三个月
<input type="radio" name="cunqi" value="6" onClick="return chkcq()"> 六个月
<input type="radio" name="cunqi" checked value="12" onClick="return chkcq()"> 一 年<br>
<input type="radio" name="cunqi" value="24" onClick="return chkcq()"> 二 年
<input type="radio" name="cunqi" value="36" onClick="return chkcq()"> 三 年
<input type="radio" name="cunqi" value="60" onClick="return chkcq()"> 五 年<br>
<span style="font-family: 宋体; font-size: 9pt">(零存整取和存本取息的存期只有一年、三年和五年)</span><span
style="font-family: 宋体; font-size: 11pt"> </span></td>
</tr>
<tr align="center">
<td width="356">存款日期: <input type="text" name="txtdate" size="10"
value="20170101" onChange="return chkdate()"> <br>
<span style="font-family: 宋体; font-size: 9pt">(存款日期最早不超过1993年5月15日,日期格式为:20000101)
</span></td>
</tr>
<tr align="center">
<td width="356"><span style="font-family: 宋体; font-size: 11pt">存入本金:</span> <input
type="text" name="txt" size="12" maxlength="10" tabindex="1" onChange="return chktxtbj()"><span
style="font-family: 宋体; font-size: 11pt"> 元</span><br>
<span style="font-family: 宋体; font-size: 9pt">(存本取息5000元起存;零存整取为每月固定存入本金数,5元起存)
</span></td>
</tr>
<tr align="center">
<td height="27" width="356" bgcolor="#88C4FF"><font color="#88C4FF"><input type="submit"
value="计算" name="B1" onClick="result()">
<input type="reset" value="重输"
name="B2"> </font></td>
</tr>
</table>
</form><br>
<br>
</body>
</html>