这是我的脚本:
<script>
jQuery(document).ready(function () {
jQuery('#btnCalculate').click(function () {
var salaries = parseInt(jQuery('#txtEmployeeSalaries').val(), 10);
var nationalInsurance = parseInt(jQuery('#txtENIC').val(), 10);
var pensionCont = parseInt(jQuery('#txtEPC').val(), 10);
var expenses = parseInt(jQuery('#txtAnyExpenses').val(), 10);
var income = parseInt(jQuery('#txtIncome').val(), 10);
var labourCost = (((salaries + nationalInsurance + pensionCont + expenses) / (income)) * 100);
alert(labourCost);
jQuery('#txtTotal').val(labourCost).toFixed(2);
});
});
</script>然而,在Chrome控制台中,它显示:
Uncaught TypeError: Object [object Object] has no method 'toFixed'
有没有人觉得这有什么明显的问题?
发布于 2013-05-28 18:35:31
这样使用toFixed -(你得到的错误是因为你试图在jquery对象上使用这个方法)
jQuery('#txtTotal').val(labourCost.toFixed(2));发布于 2013-05-28 18:35:12
你把toFixed()放错地方了。(toFixed()适用于数字,但您已将其应用于jQuery对象,而不是labourCost中的数字。)使用:
jQuery('#txtTotal').val(labourCost.toFixed(2));https://stackoverflow.com/questions/16789824
复制相似问题