Jquery计算器不起作用

时间:2015-07-22 03:07:01

标签: javascript jquery html

我遇到了如何使用jquery显示结果的问题。这是我的jsfiddle。它运行不正常。请帮我解决。

我想要的是每当我点击计算时,函数的计算结果将显示在结果范围内。

如果你想看到,我的html和javascript标签:

        <input type="text" id="loan_amount" placeholder="Loan Amount"><br />
        <input type="text" id="interest_rate" placeholder="Interest Rate"><br />
        <input type="text" id="payments_per_year" placeholder="Payments Per Year"><br />
        <input type="text" id="years" placeholder="Years"><br />
        <input type="text" id="payment" placeholder="Payment"><br />
        <input type="button" id="submit" value="Calculate">
        <span class="results"></span>

这是我的javascript / jquery代码:

$(document).ready(function(){

$("#submit").click(function(){
            var loan_amount = $("#loan_amount").val();
            var interest_rate = $("#interest_rate").val();
            var payments_per_year = $("#payments_per_year").val();
            var years = $("#years").val();
            var payment = $("#payment").val();


            function computeSchedule(loan_amount, interest_rate, payments_per_year, years, payment) {
                var schedule = [];
                var remaining = loan_amount;
                var number_of_payments = payments_per_year * years;

                    for (var i=0; i<=number_of_payments; i++) {
                        var interest = remaining * (interest_rate/100/payments_per_year);
                        var principle = (payment-interest);
                        var row = [i, principle>0?principle:0, interest>0?interest:0, remaining>0?remaining:0];
                        schedule.push(row);
                        remaining -= principle
                    }

                return schedule;
            }
        }); 
});

请帮帮我。

0 个答案:

没有答案