This. The num=0,//loan amount
This. The year=0,//loan fixed number of year
Enclosing yearRate=0,//apr
Enclosing type=0,//loan
This. The output={
Amount: 0,//monthly month for
Zonglixi: 0,//total interest
Hkprice: 0,//reimbursement amount
}
//calculation method of principal and interest waiting for the forehead
This. Benxi=function () {
Var month=parseInt (this year) * 12;//reimbursement months
Var monthRate=parseFloat (enclosing yearRate)/12;//month for
Var dknum=parseFloat (enclosing num) * 10000;//loan amount
Var amount=(monthRate dknum * * math.h pow ((1 + monthRate), month))/(math.h pow ((1 + monthRate), month) - 1)//monthly month for
Var zonglixi=month * amount - dknum;//=total interest repayment months * monthly month for the loan amount
-Var hkprice=zonglixi + dknum;//=total interest repayment amount + loan amount
This. The output. The amount=amount. ToFixed (2)
This. The output. Zonglixi=zonglixi. ToFixed (2)
This. The output. Hkprice=hkprice. ToFixed (2)
}
This. Benjin=function () {
Var month=parseInt (this year) * 12;//reimbursement months
Var monthRate=parseFloat (enclosing yearRate)/12;//month for
Var dknum=parseFloat (enclosing num) * 10000;//loan amount
Var everymonth=dknum/month;//monthly loan amount/months reimbursement should also amount=
Var amount=dknum/month + dknum * monthRate;
Var zonglixi=((everymonth + dknum * monthRate) + dknum/month * (1 + monthRate))/2 * month - dknum;
Var hkprice=zonglixi + dknum;
This. The output. The amount=amount. ToFixed (2)
This. The output. Zonglixi=zonglixi. ToFixed (2)
This. The output. Hkprice=hkprice. ToFixed (2)
}
}
Var house=new house ();
The function getinput () {
Var dknum=document. GetElementById (' dknum). The value;
Var year=document. GetElementById (' yearx). The value;
Var yearlilv=document. GetElementById (' box2.) the value;
Var Obj=document. GetElementById (' box '). The value;
House. Num=dknum;
House. Year=year;
House. YearRate=yearlilv;
House. Type=Obj.
Return true
}
The function showResult () {
Var result=[house. The output amount, house. The output. The zonglixi, house. The output. The hkprice]
Var text=[' monthly ', 'total interest', 'total payments]
Var HTML='& lt; Tr>
for(var i=0; i
HTML +='& lt; Tr>
Otable. InnerHTML=HTML;
}
}
The function result () {
If (getinput ()) {
If (house. Type==0) {
House. Benxi ();
}
If (house. Type==1) {
House. Benjin ();
}
ShowResult ();
}
}
<body>
Loan amount: & lt;/span>
Loan fixed number of year: & lt;/span>
Interest: & lt;/span>