我對jQuery很新,需要根據用戶放置在2個文本框中的內容來創建計算。JQuery計算錯誤:「未捕獲的類型錯誤:對象[對象對象]沒有方法'值'」
我的形式如下:
<tr>
<td with='110'>£ $ProductCostEach</td>
<td with='110'>Per tile</td>
<td width='55'>
<input type='hidden' name='pid' id='pid' value='$ProductID' />
<input name='quantity' class='quantity' type='text' size='1' maxlength='4' value='1' style='width:40px;' />
</td>
<td width='110'>
<button type='submit' class='red'><span class='buy'>Add to basket</span></button>
</td>
</tr><tr>
<td with='110'>£ $ProductCostPerMeter</td>
<td with='110'>Per Meter $TileSize</td>
<td width='55'>
<input type='hidden' name='pid' id='pid' value='$ProductID' />
<input name='msq' class='msq' type='text' size='1' maxlength='4' value='1' style='width:40px;' />
</td>
<td width='110'>
<button type='submit' class='red'><span class='buy'>Add to basket</span></button>
</td>
</tr>
現在,當用戶輸入與一類.msq我希望它進行計算的輸入框的值,所以寫了一個keyup事件:
function roundNumber(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}
var convMultiplier
convMultiplier = 0.0625
$('.msq').bind('keyup', function(){
var qty_text_box = $(this).parent().parent().parent().find('.quantity');
qty_text_box.value(roundNumber($(this).value * convMultiplier, 2));
});
但有一個問題剛剛得到輸入框的值。如果我在var qty_text_box = $(this).parent()。parent()。parent()。find('。quantity');後添加alert(qty_text_box.value())我得到一個錯誤「遺漏的類型錯誤:對象的翻譯:有沒有方法‘價值’」
但我在努力工作,出了什麼問題?
提前許多感謝,
大連