我有當值手動設置爲什麼我的javascript函數只有在手動輸入輸入時才起作用?
function doSomeMath(array,number){
some math here.....
}
它只有當我設置的每月賬單的作品完美的作品函數手動
function customer(){
this.monthlyBill = 300;
}
當我做到這一點,它工作正常:
var someArray = [.2,.3,.6];
var customerData = new customer();
doSomeMath(someArray,customerData.monthlyBill);
問題是我不想手動設置它,我想從表單輸入元素獲取值。
當我做到這一點弄亂:
function customer(){
this.monthlyBill = $('#monthly_bill').val();
}
我去在300 #monthly_bill形式和類型,我得到一個完全不同的值。
是什麼打字
this.monthlyBill = 300
和
this.monthlyBill = $('#monthl_bill').val(); // and then typing 300 into a form.
300是一個數字 - xxx.val()是一個字符串 - 嘗試'parseInt函數($('#monthl_bill ').val(),10);' – mplungjan 2012-04-17 11:26:57