私はこれを行うと、手動でなぜ私のjavascript関数は、手動で入力を入力した場合にのみ機能するのですか?
function customer(){
this.monthlyBill = 300;
}
それが正常に動作した値を手動で私は毎月の請求書を設定する場合にのみ動作します
function doSomeMath(array,number){
some math here.....
}
設定されている場合完璧に動作機能を持っている:
var someArray = [.2,.3,.6];
var customerData = new customer();
doSomeMath(someArray,customerData.monthlyBill);
問題は手動で設定したくないということです。フォームの入力要素から値を取得したいのです。
私はこれを行うと、それは台無し:
function customer(){
this.monthlyBill = $('#monthly_bill').val();
}
私は300で#monthly_billフォームとタイプに行くと、私は完全に別の値を取得します。私との違いは、それが文字列とみなされる第2のケースで
this.monthlyBill = 300
と
this.monthlyBill = $('#monthl_bill').val(); // and then typing 300 into a form.
300は、数ある意味ので、誰かが有力0を入力する - xxx.val()文字列です - $( '#monthl_bill( 'のparseIntを試してみてください').val()、10); ' – mplungjan