使用文本输入字段时出现的JN中的NaN

Phi*_*ins 2 html javascript jquery input function

我正在尝试使用一个简单的javascript函数,该函数旨在与单个数字的SELECT下拉列表一起使用,但现在我需要在访问者输入带小数点的值时使用它.即使我输入30或任何数字,我使用当前的javascript获得NaN.关于如何获得我的总数的任何建议?

JAVASCRIPT:

$(function () {
    $('.DoPricing').change(function () {
        var total = 0;
        $('.DoPricing').each(function () {
            total += parseInt($(this).val());
        });
        $('#TotalPrice').html('$' + total);
    });
});
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

isJ*_*tMe 5

试试这个:

$(function () {
    $('.DoPricing').on("keyup",function () {
        var total = 0;
        $('.DoPricing').each(function () {
            total += parseFloat($(this).val()) || 0;
        });
        $('#TotalPrice').html('$' + total);
    });
});
Run Code Online (Sandbox Code Playgroud)

这现在接受小数,这是演示