js 计算银行按揭还款 及还款详细
2011-03-01 17:29
267 查看
代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>按揭贷款计算工具--QQ:83056224</title> </HEAD> <body> <form name="result01" method="post" id="result01"> <table cellpadding="0" cellspacing="0" width=563 border="0" align="center"> <tr height=10> <td></td> </tr> <tr> <td align="center"><table cellSpacing="0" cellPadding="3" width="100%" border="0"> <tr> <td><b>按揭贷款计算(等额本息还款/等额本金还款)</b></td> </tr> <tr> <td align=center> <table cellpadding=3 bgcolor="#f5f5f5" style="BORDER-RIGHT: #c6c9ce 1px solid; BORDER-TOP: #c6c9ce 1px solid; BORDER-LEFT: #c6c9ce 1px solid; BORDER-BOTTOM: #c6c9ce 1px solid; BORDER-COLLAPSE: collapse" borderColor="#c6c9ce" cellSpacing="0" width="98%"> <tr> <td width=5></td> <td>贷款金额:</td> <td class="hui11"><input id="total" type="text" style="WIDTH: 100px; HEIGHT: 22px" size="18"> 元</td> <td>贷款期限:</td> <td class="hui11"><input id="termnum" style="WIDTH: 60px; HEIGHT: 22px" type="text" size="10"> 月(1-360)</td> <td width=5></td> </tr> <tr> <td></td> <td>贷款年利率:</td> <td class=hui11><input id="yearrate" style="WIDTH: 60px; HEIGHT: 22px" type="text" size="10"> %</td> <td colspan=3><input name=payfun type=radio id="radiode" value="de">等额本息还款 <input name=payfun type=radio id="radiodj" value="dj"/>等额本金还款</td> </tr> <Tr><td></td><td background="/house/images/Calculators_line2.GIF" colspan=4 height=5></td><td></td></tr> <tr> <td></td><td align="middle" colSpan="4"><input onclick="CalculateMonth(this.form)" type="button" value="计算"> <input onclick="Reset(this.form)" type="button" value="重置"></td><td></td> </tr> </table> </td> </tr> <tr style="display:none"> <td align=center> <table cellpadding=3 style="BORDER-RIGHT: #c6c9ce 1px solid; BORDER-TOP: #c6c9ce 1px solid; BORDER-LEFT: #c6c9ce 1px solid; BORDER-BOTTOM: #c6c9ce 1px solid; BORDER-COLLAPSE: collapse" borderColor="#c6c9ce" cellSpacing="0" rules="all" width="98%" border="1"> <tr> <td width="90" height=24 bgcolor="#dbdbdb" align=center>还款方式</td> <td width="80" bgcolor="#dbdbdb" align=center>还款总额</td> <td width="80" bgcolor="#dbdbdb" align=center>利息总额</td> <td bgcolor="#dbdbdb" align=center>月还款金额</td> </tr> <tr> <td bgcolor="#f5f5f5" align=center>等额本息还款</td> <td align=center><input id="totalpay1" readonly style="BORDER-LEFT-COLOR: white; BORDER-BOTTOM-COLOR: white; WIDTH: 80px; BORDER-TOP-STYLE: none; BORDER-TOP-COLOR: white; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-RIGHT-COLOR: white; BORDER-BOTTOM-STYLE: none" type="text"></td> <td align=center><input id="ratetotal1" readonly style="BORDER-LEFT-COLOR: white; BORDER-BOTTOM-COLOR: white; WIDTH: 80px; BORDER-TOP-STYLE: none; BORDER-TOP-COLOR: white; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-RIGHT-COLOR: white; BORDER-BOTTOM-STYLE: none" type="text"></td> <td align=center><textarea id="monthpay1" readonly style="WIDTH: 230px; HEIGHT: 62px" rows="4" cols="25"></textarea></td> </tr> <tr> <td bgcolor="#f5f5f5" align=center>等额本金还款</td> <td align=center><input id="totalpay2" readonly style="BORDER-LEFT-COLOR: white; BORDER-BOTTOM-COLOR: white; WIDTH: 80px; BORDER-TOP-STYLE: none; BORDER-TOP-COLOR: white; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-RIGHT-COLOR: white; BORDER-BOTTOM-STYLE: none" type="text"></td> <td align=center><input id="ratetotal2" readonly style="BORDER-LEFT-COLOR: white; BORDER-BOTTOM-COLOR: white; WIDTH: 80px; BORDER-TOP-STYLE: none; BORDER-TOP-COLOR: white; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-RIGHT-COLOR: white; BORDER-BOTTOM-STYLE: none" type="text"></td> <td align=center bgcolor="#f5f5f5" height=74><textarea id="monthpay2" readonly style="WIDTH: 230px; HEIGHT: 62px" rows="4" cols="25"></textarea></td> </tr> </table> </td> </tr> </table> <script language="javascript"> function Reset(obj) { event.returnValue = false; obj.total.value = ""; obj.yearrate.value = ""; obj.termnum.value = ""; obj.totalpay1.value = ""; obj.totalpay2.value = ""; obj.ratetotal1.value = ""; obj.ratetotal2.value = ""; obj.monthpay1.value = ""; obj.monthpay2.value = ""; } function CalculateMonth(obj) { event.returnValue = false; var payfunc; var sflag = false; if (obj.total.value == "") { alert("请输入贷款金额!"); return; } if (obj.yearrate.value == "") { alert("请输入贷款年利率!"); return; } if (obj.termnum.value == "") { alert("请输入贷款总期数!"); return; } for (i=0; i<obj.payfun.length;i++) { if (obj.payfun[i].checked==true) { payfunc = obj.payfun[i].value; sflag = true; } } if (sflag==false) { alert("请选择还款方式!"); return; } var total = obj.total.value; var yearrate = obj.yearrate.value; var terms = obj.termnum.value; if ((terms <= 0)||(terms >360)) { alert("贷款月数输入不正确!"); return; } if (total <= 0) { alert("贷款总额输入不正确!"); return; } if ((yearrate <= 0)||(yearrate >=100)) { alert("贷款年利率输入不正确!"); return; } Get(total,yearrate,terms,payfunc); /* var monthpay1 = MyRound(GetMonthPay1(total,yearrate,terms)); var lastmonthpay1 = MyRound(GetLastMonthPay1(total,yearrate,terms,monthpay1)); var totalpay1 = MyRound(monthpay1*(terms-1)+lastmonthpay1); var totalrate1 = MyRound(totalpay1-total); obj.totalpay1.value = totalpay1; obj.ratetotal1.value = totalrate1; //obj.monthpay1.value = "前"+(terms-1)+"月月还款为:"+monthpay1+","; //obj.monthpay11.value = "最后月月还款为:"+lastmonthpay1; var totalpay2 = 0; var totalrate2 = 0; var monthpay2 = 0; obj.monthpay1.value = ""; obj.monthpay2.value = ""; for (k=0;k<terms-1;k++) { monthpay2 = MyRound(GetMonthPay2(total,yearrate,terms,k)); totalpay2 = MyRound(totalpay2+monthpay2); obj.monthpay2.value += "第"+(k+1)+"月还款:"+monthpay2+"/r/n"; obj.monthpay1.value += "第"+(k+1)+"月还款:"+monthpay1+"/r/n"; } var lastmonthpay2 = MyRound(GetLastMonthPay2(total,yearrate,terms)); totalpay2 = MyRound(totalpay2 + lastmonthpay2); obj.monthpay2.value += "第"+terms+"月还款:"+lastmonthpay2+"/r/n"; obj.monthpay1.value += "第"+terms+"月还款:"+lastmonthpay1+"/r/n"; totalrate2 = MyRound(parseFloat(totalpay2)-total); obj.totalpay2.value = totalpay2; obj.ratetotal2.value = totalrate2;*/ } function ChangeMonthType(obj) { obj.yearrate.value = GetYearRate(parseInt(obj.paytype.options[obj.paytype.selectedIndex].value),parseInt(obj.termnum.value)/12); } //ChangeMonthType(document.Calculators); </script></td> </tr> <tr height=8> <td></td> </tr> <tr style="display:none" id="de"> <td><table cellpadding="3" style="BORDER-COLLAPSE: collapse" align="center" borderColor="#c6c9ce" cellSpacing="0" rules="all" width="546" border="1"> <tr> <td width="90" height="24" bgcolor="#dbdbdb" align="center">还款方式</td> <td align="center">等额本息还款</td> <td width="80" bgcolor="#dbdbdb" align="center">还款总额</td> <td align="center"><input id="detotalpay1" readonly style="BORDER-LEFT-COLOR: white; BORDER-BOTTOM-COLOR: white; WIDTH: 80px; BORDER-TOP-STYLE: none; BORDER-TOP-COLOR: white; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-RIGHT-COLOR: white; BORDER-BOTTOM-STYLE: none" type="text"></td> <td width="80" bgcolor="#dbdbdb" align="center">利息总额</td> <td align="center"><input id="deratetotal1" readonly style="BORDER-LEFT-COLOR: white; BORDER-BOTTOM-COLOR: white; WIDTH: 80px; BORDER-TOP-STYLE: none; BORDER-TOP-COLOR: white; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-RIGHT-COLOR: white; BORDER-BOTTOM-STYLE: none" type="text"></td> </tr> </table> <table cellpadding="0" align="center" cellSpacing="0" width="563" border="0"> <tr height="10"> <td></td> </tr> </table> <div id="calRdiv"></div> </td> </tr> <tr style="display:none" id="dj"> <td> <table cellpadding="3" style="BORDER-COLLAPSE: collapse" align="center" borderColor="#c6c9ce" cellSpacing="0" rules="all" width="546" border="1"> <tr> <td width="90" height="24" bgcolor="#dbdbdb" align="center">还款方式</td> <td align="center">等额本金还款</td> <td width="80" bgcolor="#dbdbdb" align="center">还款总额</td> <td align="center"><input id="djtotalpay2" readonly style="BORDER-LEFT-COLOR: white; BORDER-BOTTOM-COLOR: white; WIDTH: 80px; BORDER-TOP-STYLE: none; BORDER-TOP-COLOR: white; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-RIGHT-COLOR: white; BORDER-BOTTOM-STYLE: none" type="text"></td> <td width="80" bgcolor="#dbdbdb" align="center">利息总额</td> <td align="center"><input id="djratetotal2" readonly style="BORDER-LEFT-COLOR: white; BORDER-BOTTOM-COLOR: white; WIDTH: 80px; BORDER-TOP-STYLE: none; BORDER-TOP-COLOR: white; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-RIGHT-COLOR: white; BORDER-BOTTOM-STYLE: none" type="text"></td> </tr> </table> <table cellpadding="0" align="center" cellSpacing="0" width="563" border="0"> <tr height="10"> <td></td> </tr> </table> <div id="calCdiv"><FONT face="宋体"></FONT></div> </td> </tr> <tr><td>转载注明出处!QQ:83056224</td></tr> </table> <script language="javascript"> function Get(total,yearrate,terms,payfun) { var total = total; var yearrate = yearrate; var terms = terms; var payfun = payfun; var obj = document.result01; obj.total.value = total; obj.yearrate.value = yearrate; obj.termnum.value = terms; for(j=0;j<obj.payfun.length;j++) { if(obj.payfun[j].value==payfun) { obj.payfun[j].checked = true; } } if(payfun=="de") { de.style.display = ""; } if(payfun=="dj") { dj.style.display = ""; } function calRate() { var corpus=parseFloat(total); var rates=(parseFloat(yearrate))/100/12; var rateMon=parseInt(terms); var sbResult=calculateR(rates,rateMon,corpus); document.getElementById("calRdiv").innerHTML=sbResult; sbResult=calculateC(rates,rateMon,corpus); document.getElementById("calCdiv").innerHTML=sbResult; } //计算等额还款 function calculateR(rates,rateMon,corpus)//利率、期限、本金 { var limitTime=rateMon;//贷款期限 var timeLeft=limitTime; var corpusLeft=corpus;//等额还款之本金 var corpusLeftMon=corpus;//等额还款之剩余本金 var capMon,corpusMon,varerestMon; var capTotle=0,corpusTotle=0,varerestTotle=0; var sbResultR; var rate=rates; sbResultR=createTable(sbResultR); for(var i=1;i<limitTime;i++) { var ratePow=Math.pow(rate+1,timeLeft);//每期贷款利率 capMon=(corpusLeft*rate*ratePow)/(ratePow-1);//月供 varerestMon=corpusLeftMon*rate;//月供利息 corpusMon=capMon-varerestMon;//月供本金 corpusLeftMon-=corpusMon;//本金余额 capTotle+=capMon;//还款总额 varerestTotle+=varerestMon;//利息总额 corpusTotle+=corpusMon;//本金总额 sbResultR=output(sbResultR,i,capMon,varerestMon,corpusMon,corpusLeftMon,rate*12*100); } ///最后一期 //alert(corpusLeftMon); varerestMon=corpusLeftMon*rate;//月供利息 corpusMon=corpusLeftMon;//月供本金 capMon=varerestMon + corpusLeftMon;//月供 corpusLeftMon-=corpusMon;//本金余额 capTotle+=capMon;//还款总额 varerestTotle+=varerestMon;//利息总额 corpusTotle+=corpusMon;//本金总额 sbResultR=output(sbResultR,limitTime,capMon,varerestMon,corpusMon,corpusLeftMon,rate*12*100); sbResultR=output(sbResultR,9999,capTotle,varerestTotle,corpusTotle,corpusLeftMon,0); sbResultR=endTable(sbResultR); obj.detotalpay1.value = (Math.round(capTotle*100))/100;//还款总额 obj.deratetotal1.value = (Math.round(varerestTotle*100))/100;//利息总额 return sbResultR; } //计算等额本金 function calculateC( rates,rateMon,corpus) { var limitTime=rateMon; var timeLeft=limitTime; var corpusLeftMon=corpus;//等额本金之剩余本金 var capMon,corpusMon,varerestMon; var capTotle=0,varerestTotle=0,corpusTotle=0; corpusMon=corpus/limitTime; var rate=rates; var sbResultC; sbResultC=createTable(sbResultC); for(var i=1;i<=limitTime;i++) { varerestMon=corpusLeftMon*rate; capMon=corpusMon+varerestMon; corpusLeftMon-=corpusMon; capTotle+=capMon; varerestTotle+=varerestMon; corpusTotle+=corpusMon; sbResultC=output(sbResultC,i,capMon,varerestMon,corpusMon,corpusLeftMon,rate*12*100); } sbResultC=output(sbResultC,9999,capTotle,varerestTotle,corpusTotle,0,0); sbResultC=endTable(sbResultC); obj.djtotalpay2.value = (Math.round(capTotle*100))/100;//还款总额 obj.djratetotal2.value = (Math.round(varerestTotle*100))/100;//利息总额 return sbResultC; } function createTable(sbResult) { sbResult="<table cellpadding=3 style='BORDER-COLLAPSE: collapse' align=center borderColor=#c6c9ce cellSpacing=0 rules=all width=546 border=1>"; sbResult+="<tr height=24><td width=20% bgcolor=#dbdbdb align=center>期数</td><td width=20% bgcolor=#dbdbdb align=center>月供</td><td width=20% bgcolor=#dbdbdb align=center>月供本金</td><td width=20% bgcolor=#dbdbdb align=center>月供利息</td><td width=20% bgcolor=#dbdbdb align=center>本金余额</td></tr>"; return sbResult; } function endTable(sbResult) { sbResult+="</table>"; return sbResult; } function formatnumber(num) { var dotIndex=num.indexOf("."); var length=num.length; if(dotIndex==length-2) {num=num+"0";} switch(dotIndex){ case -1:num=num+".00";break; // case 2:num=num+"0";break; default:break;} /* var length=num.length; if(dotIndex==-1) {num=num+".00"; return num; } if(dotIndex==length-1) {num+"0";return num;}*/ return num; } function output(sbResult,month,cap,varerest,corpus,corpusLeftMon,rate) { sbResult+="<tr><td align=center>"; if(month==9999) sbResult+="总计"; else sbResult+=month.toString(); cap=(Math.round(cap*100))/100; sbResult+="</td><td align=middle><input name='repayment' id='repayment_" + month + "' type='text' size='10' maxlength='64' value='"+formatnumber(cap.toString())+"'"; sbResult+="</td><td align=middle>"; corpus=(Math.ceil(corpus*100))/100; sbResult+=formatnumber(corpus.toString()); sbResult+="</td><td align=middle>"; varerest=(Math.round(varerest*100))/100; sbResult+=formatnumber(varerest.toString()); sbResult+="</td><td align=middle>"; if(month==9999) { sbResult+="---"; sbResult+="</td>"; //sbResult+="---"; } else { corpusLeftMon=(Math.round(corpusLeftMon*100))/100; sbResult+=formatnumber(corpusLeftMon.toString()); sbResult+="</td>"; //rate=(Math.round(rate*1000))/1000 //sbResult+=rate.toString(); } sbResult+="</tr>"; return sbResult; } calRate(); } </script> </form> </body> </HTML>
相关文章推荐
- 计算银行还款 等额本金 85折 20年
- 购房房贷按揭利息计算方法个人房贷按揭还款3方式
- node.js零基础详细教程(1):安装+基础概念
- JS执行上下文(执行环境)详细图解
- js中apply方法的使用详细解析
- Vue.js—计算属性
- 压缩跟踪(CT)代码详细学习_模块2(特征的提取和计算)
- nodejs+npm+gulp使用详细教程
- 搞定immutable.js详细说明
- js动态计算移动端rem
- js中cookie的使用详细分析
- Require.js 详细了解
- js 计算时间差及比较日期大小
- vuejs教程3-计算属性
- 太阳能光伏发电和路灯应用系统的详细计算
- JS 计算Object长度(二)
- JS获取dom元素计算样式大小
- [置顶] 让你详细了解js闭包问题
- luhn计算最后一位校验位(ICCID,银行卡号)
- js计算当前日期上一个月和下一个月