我嘗試使用旨在用單一數字的選擇下拉使用JavaScript的一個簡單的功能時,但現在我需要用它來當遊客輸入一個帶有小數點的值。即使在輸入30或任何數字時,我也會獲得當前JavaScript的NaN。有關如何獲得我的總數的任何建議?楠的Javascript顯示了使用文本輸入字段
JAVASCRIPT:
$(function() {
$('.DoPricing').change(function() {
var total = 0;
$('.DoPricing').each(function() {
total += parseInt($(this).val());
});
$('#TotalPrice').html('$' + total);
});
});
HTML:
<form action="myactionpage.php" method="POST">
<table>
<tr>
<td>How much will you be paying today?</td>
<td>$<input type="text" name="howmuch" id="howmuch" placeholder="0.00" class="DoPricing"></td>
</tr>
<tr>
<td><div class="totalbox">Total Amount Due Today: <strong><span id="TotalPrice">$0.00</span></strong></div>
</td>
</tr>
<tr><td><input type="submit" id="submit" name="submit" value="Submit Payment" class="submitbut" /></td>
</tr>
</table>
</form>
製作小提琴,以獲得更多的反應...! –
您是否有多個輸入框和一個dopricing類? – HMR
使用'parseInt函數()'你應該總是通過第二個參數的功能說明您正在使用的基地(您需要什麼'parseInt函數($(本).VAL(),10)'否則的08和I輸入如果你需要輸入十進制值,使用'parseFloat()'而不是'parseInt()'(注意''parseFloat()''不帶底座的說法,它總是隻能以10爲基數又名十進制) –