如何在 jQuery 中添加两个整数值并在 $ ammount 中输出


How to add two integer values in jQuery and have an output in $ ammount

我有以下代码:

  $(document).ready(function(){
    $('input').iCheck ({
      checkboxClass: 'icheckbox_square-blue',
      radioClass: 'iradio_square-blue',
      increaseArea: '20%' // optional
   });
    var sum = 0;
    $(".btn-checkbox-choice").blur(function(){
       $(this).parseNumber({format:"#,###.00", locale:"us"});
       $(this).formatNumber({format:"#,###.00", locale:"us"});
   });
    $(".btn-checkbox-plan").blur(function(){
       $(this).parseNumber({format:"#,###.00", locale:"us"});
       $(this).formatNumber({format:"#,###.00",locale:"us"});
    });
    $('input').on('ifChecked', function(event){
      if($(".btn-checkbox-plan").is(':checked')){
         $("#output").html($(this).val());
    }
      else if($(".btn-checkbox-choice").is(':checked')){
         $("#output-choice").html($(this).val());
         }
   });
      if($('.btn-checkbox-choice').is(':checked') && $('.btn-checkbox-plan').is(':checked')){
        sum = parseInt($('.btn-checkbox-choice').val()) + parseInt($('.btn-checkbox-plan').val());
        //alert(sum);
       $('#output').html(sum);
               //console.log(sum);
    }
  });

结帐.php

 <div class="answerswer">
    <input class="btn-checkbox-choice" type="radio" name="groupeight" value="49.99" <?php if (!isset($_POST['radio']) || isset($_POST['radio']) && $_POST['radio'] == '49.99'): ?>checked="checked"<?php endif; ?> /><label>Yes</label></div>
    <input class="btn-checkbox-choice" type="radio" name="groupeight" value="0.00" <?php if (!isset($_POST['radio']) || isset($_POST['radio']) && $_POST['radio'] == '0.00'): ?>checked="checked"<?php endif; ?> /><label>No</label><br />
 <label id="silver-plan"><input class="btn-checkbox-plan" type="radio" name="groupnine" value="699" <?php if (!isset($_POST['radio']) || isset($_POST['radio']) && $_POST['radio'] == '699'): ?>checked="checked"<?php endif; ?> /><label>Silver Plan</label><span id="silver-plan-price">$699</span></label>
 <label id="gold-plan"><input class="btn-checkbox-plan" type="radio" name="groupnine" value="999" <?php if (isset($_POST['radio']) && $_POST['radio'] == '999'): ?>checked="checked"<?php endif; ?>/><label>Gold Plan</label><span id="gold-plan-price">$999</span></label>

我正在尝试输出 .btn 复选框计划和 .btn-选择计划的总价格,总金额前面有 $ 符号。但是,我的代码不起作用。我没有得到 .btn-复选框计划和 .btn-choice-plan 的总和;但是,单选按钮单独工作。如果我单击.btn复选框选择,如果用户选择"是",则得到49.99,如果用户选择"否",则得到0.00。然后,如果我单击.btn复选框计划,它将被699或999覆盖,具体取决于我单击了银级还是金色计划。我做错了什么?我怎样才能得到这些整数的总和,前面有 $?

对于 $ 符号,我使用了以下源 https://code.google.com/p/jquery-numberformatter/

获得正确格式的价格后,只需使用字符串连接在 sum 变量中添加一个"$"。

sum = "$" + sum;
$('#output').html(sum);