我是javascript的菜鸟。我需要对代码进行一些更改,但它不会在keyup上返回值。请帮我解决一下这个。谢谢大家。
顺便说一句,我在Wordpress Page中使用此代码。当我检查控制台时,它显示语法错误。
我希望得到结果,但不会返回任何内容。
window.jQuery || document.write('<script src="js/vendor/jquery-1.12.0.min.js"><\/script>')
jQuery(document).ready(function($) {
var TrT = {};
TrT.ExGST = function(B2, Term) {
// 24 month
if (Term == 24 && B2 >= 500 && B2 <= 3499) {
return (B2 + 150) * (1 + 0.08) * 4.986 / 100
} else if (Term == 24 && B2 >= 3500 && B2 <= 7999) {
return (B2 + 150) * (1 + 0.08) * 4.62 / 100
} else if (Term == 24 && B2 >= 8000 && B2 <= 29999) {
return (B2 + 150) * (1 + 0.0725) * 4.62 / 100
} else if (Term == 24 && B2 >= 30000 && B2 <= 49999) {
return (B2 + 150) * (1 + 0.0625) * 4.6 / 100
} else if (Term == 24 && B2 >= 50000 && B2 <= 200000) {
return (B2 + 150) * (1 + 0.0525) * 4.6 / 100
}
// 36 month
if (Term == 36 && B2 >= 500 && B2 <= 3499) {
return (B2 + 150) * (1 + 0.08) * 3.33 / 100
} else if (Term == 36 && B2 >= 3500 && B2 <= 7999) {
return (B2 + 150) * (1 + 0.08) * 3.23 / 100
} else if (Term == 36 && B2 >= 8000 && B2 <= 29999) {
return (B2 + 150) * (1 + 0.0725) * 3.17 / 100
} else if (Term == 36 && B2 >= 30000 && B2 <= 49999) {
return (B2 + 150) * (1 + 0.0625) * 3.167 / 100
} else if (Term == 36 && B2 >= 50000 && B2 <= 200000) {
return (B2 + 150) * (1 + 0.0525) * 3.14 / 100
}
// 48 month
if (Term == 48 && B2 >= 500 && B2 <= 3499) {
return (B2 + 150) * (1 + 0.08) * 2.59 / 100
} else if (Term == 48 && B2 >= 3500 && B2 <= 7999) {
return (B2 + 150) * (1 + 0.08) * 2.5 / 100
} else if (Term == 48 && B2 >= 8000 && B2 <= 29999) {
return (B2 + 150) * (1 + 0.0725) * 2.45 / 100
} else if (Term == 48 && B2 >= 30000 && B2 <= 49999) {
return (B2 + 150) * (1 + 0.0625) * 2.43 / 100
} else if (Term == 48 && B2 >= 50000 && B2 <= 200000) {
return (B2 + 150) * (1 + 0.0525) * 2.39 / 100
}
// 60 month
if (Term == 60 && B2 >= 500 && B2 <= 3499) {
return (B2 + 150) * (1 + 0.08) * 2.25) / 100
} else if (Term == 60 && B2 >= 3500 && B2 <= 7999) {
return (B2 + 150) * (1 + 0.08) * 2.075 / 100
} else
if (Term == 60 && B2 >= 8000 && B2 <= 29999) {
return (B2 + 150) * (1 + 0.0725) * 2.02 / 100
} else if (Term == 60 && B2 >= 30000 && B2 <= 49999) {
return (B2 + 150) * (1 + 0.0625) * 2.015 / 100
} else if (Term == 60 && B2 >= 50000 && B2 <= 200000) {
return (B2 + 150) * (1 + 0.0525) * 1.90 .08
}
return 0
};
TrT.totalFinance = function() {
let B2 = parseFloat($("#invoice").val());
let Term = $("#term").val();
let monthlyRentel = TrT.ExGST(B2, Term);
$('#monthlyex').val(TrT.roundN(monthlyRentel));
$('#monthlygst').val(TrT.roundN(monthlyRentel * 0.1));
$('#monthlyinc').val(TrT.roundN(monthlyRentel * 1.1));
}; TrT.monthly = function(B2, Term) {
// 24 month
if (Term == 24 && B2 >= 2428.01 && B2 <= 9690.26) {
return (B2 * 100) / ((1 + 0.0525) * 4.6) - 150
} else if (Term == 24 && B2 >= 1473.58 && B2 <= 2451.03) {
return (B2 * 100) / ((1 + 0.0625) * 4.6) - 150
} else if (Term == 24 && B2 >= 403.83 && B2 <= 1493.87) {
return (B2 * 100) / ((1 + 0.0725) * 4.62) - 150
} else if (Term == 24 && B2 >= 182.12 && B2 <= 406.60) {
return (B2 * 100) / ((1 + 0.08) * 4.62) - 150
} else if (Term == 24 && B2 >= 35 && B2 <= 196.49) {
return (B2 * 100) / ((1 + 0.08) * 4.986) - 150
}
// 36 month
if (Term == 36 && B2 >= 1657.38 && B2 <= 6614.66) {
return (B2 * 100) / ((1 + 0.0525) * 3.14) - 150
} else if (Term == 36 && B2 >= 1014.53 && B2 <= 1687.48) {
return (B2 * 100) / ((1 + 0.0625) * 3.167) - 150
} else if (Term == 36 && B2 >= 277.09 && B2 <= 1025.01) {
return (B2 * 100) / ((1 + 0.0725) * 3.17) - 150
} else if (Term == 36 && B2 >= 127.33 && B2 <= 284.27) {
return (B2 * 100) / ((1 + 0.08) * 3.23) - 150
} else if (Term == 36 && B2 >= 23.38 && B2 <= 131.23) {
return (B2 * 100) / ((1 + 0.08) * 3.33) - 150
}
// 48 month
if (Term == 48 && B2 >= 1261.51 && B2 <= 5034.72) {
return (B2 * 100) / ((1 + 0.0525) * 2.39) - 150
} else if (Term == 48 && B2 >= 778.44 && B2 <= 1294.78) {
return (B2 * 100) / ((1 + 0.0625) * 2.43) - 150
} else if (Term == 48 && B2 >= 214.15 && B2 <= 792.20) {
return (B2 * 100) / ((1 + 0.0725) * 2.45) - 150
} else if (Term == 48 && B2 >= 98.55 && B2 <= 220.02) {
return (B2 * 100) / ((1 + 0.08) * 2.50) - 150
} else if (Term == 48 && B2 >= 18.18 && B2 <= 102.07) {
return (B2 * 100) / ((1 + 0.08) * 2.59) - 150
}
// 60 month
if (Term == 60 && B2 >= 1045.10 && B2 <= 4171.03) {
return (B2 * 100) / ((1 + 0.0525) * 1.98) - 150
} else if (Term == 60 && B2 >= 645.49 && B2 <= 1073.66) {
return (B2 * 100) / ((1 + 0.0625) * 2.015) - 150
} else if (Term == 60 && B2 >= 176.57 && B2 <= 653.16) {
return (B2 * 100) / ((1 + 0.0725) * 2.02) - 150
} else if (Term == 60 && B2 >= 81.8 && B2 <= 182.62) {
return (B2 * 100) / ((1 + 0.08) * 2.075) - 150
} else if (Term == 60 && B2 >= 15.8 && B2 <= 88.67) {
return (B2 * 100) / ((1 + 0.08) * 2.25) - 150
}
return 0
};
TrT.monthlyFinance = function() {
let B2 = parseFloat($("#invoiceM").val());
let Term = $("#termM").val();
let monthlyRentel = TrT.monthly(B2, Term);
$('#monthlyexM').val(TrT.roundN(B2 * 1.1));
$('#monthlygstM').val(TrT.roundN(B2 * 0.1));
$('#monthlyincM').val(TrT.roundN(monthlyRentel));
};
TrT.roundN = function(N) {
return Math.round(N * 100) / 100;
};
TrT.totalFinance = function() {
let B2 = parseFloat($("#invoice").val());
let Term = $("#term").val();
let monthlyRentel = TrT.ExGST(B2, Term);
$('#monthlyex').val(TrT.roundN(monthlyRentel));
$('#monthlygst').val(TrT.roundN(monthlyRentel * 0.1));
$('#monthlyinc').val(TrT.roundN(monthlyRentel * 1.1));
};
$("#invoice").keyup(function() {
TrT.totalFinance();
});
$("#term").on('change', function() {
TrT.totalFinance();
});
$("#invoiceM").keyup(function() {
TrT.monthlyFinance();
});
$("#termM").on('change', function() {
TrT.monthlyFinance();
});
});
<div class="calculator-tabs">
<ul id="collapsing-tabs" class="tabs" data-active-collapse="true" data-tabs="">
<li class="tabs-title is-active"><a href="#panel1c" aria-selected="true">Total Amount</a></li>
<li class="tabs-title"><a href="#panel2c">Monthly Amount</a></li>
</ul>
<div class="tabs-content" data-tabs-content="collapsing-tabs">
<div id="panel1c" class="tabs-panel is-active">
<form class="calculator-version-1 calculator" data-calc_type="grenke">
<fieldset>
<div class="pure-control-group"><label for="invoice">Total Finance Amount (Ex GST):</label>
<input id="invoice" name="invoice" required="" type="text" placeholder="5000" /></div>
<div class="pure-control-group"><label for="term">Rental Term (Months):</label>
<select id="term" name="term" required="">
<option selected="selected" value="60">60</option>
<option value="48">48</option>
<option value="36">36</option>
<option value="24">24</option>
</select>
</div>
<div class="pure-control-group"><label for="monthlyex">Monthly Rental (Ex GST):</label>
<input id="monthlyex" disabled="disabled" name="monthlyex" type="text" placeholder="$0.00" /></div>
<div class="pure-control-group"><label for="monthlygst">GST Component:</label>
<input id="monthlygst" disabled="disabled" name="monthlygst" type="text" placeholder="$0.00" /></div>
<div class="pure-control-group"><label for="monthlyinc">Monthly Rental (Inc GST):</label>
<input id="monthlyinc" disabled="disabled" name="monthlyinc" type="text" placeholder="$0.00" /></div>
</fieldset>
</form>
</div>
<div id="panel2c" class="tabs-panel">
<form class="calculator-version-1 calculator" data-calc_type="grenke">
<fieldset>
<div class="pure-control-group"><label for="invoice">Monthly Finance (Ex GST):</label>
<input id="invoiceM" name="invoiceM" required="" type="text" placeholder="5000" /></div>
<div class="pure-control-group"><label for="termM">Rental Term (Months):</label>
<select id="termM" name="termM" required="">
<option selected="selected" value="60">60</option>
<option value="48">48</option>
<option value="36">36</option>
<option value="24">24</option>
</select>
</div>
<div class="pure-control-group"><label for="monthlygstM">GST Component:</label>
<input id="monthlygstM" disabled="disabled" name="monthlygstM" type="text" placeholder="$0.00" /></div>
<div class="pure-control-group"><label for="monthlyexM">Monthly Finance (Inc GST):</label>
<input id="monthlyexM" disabled="disabled" name="monthlyexM" type="text" placeholder="$0.00" /></div>
<div class="pure-control-group"><label for="monthlyincM">Total Finance (Ex GST):</label>
<input id="monthlyincM" disabled="disabled" name="monthlyinc" type="text" placeholder="$0.00" /></div>
</fieldset>
</form>
</div>
</div>
</div>
<p style="text-align: center; margin-top: 24px;"><a class="button loanezi-app-btn" href="http://loanezi.fleetninja.com/" target="_blank" rel="noopener">Go to Loanezi Application
Portal</a></p>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>