gpt4 book ai didi

javascript - 如何在 jQuery 中添加两个整数值并以 $ amount 输出

转载 作者:行者123 更新时间:2023-12-03 11:12:45 25 4
gpt4 key购买 nike

我有以下代码:

  $(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="answer">
<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-checkbox-plan 和 .btn-choice-plan 的总价格,并在总金额前面加上 $ 符号。但是,我的代码不起作用。我没有得到 .btn-checkbox-plan 和 .btn-choice-plan 的总和;然而,单选按钮单独工作。如果我单击 .btn-checkbox-choice,如果用户选择"is",则得到 49.99,如果用户选择“否”,则得到 0.00。然后,如果我单击 .btn-checkbox-plan,它会被 699 或 999 覆盖,具体取决于我单击的是白银计划还是黄金计划。我究竟做错了什么?如何获得这些前面带有 $ 的整数的总和?

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

最佳答案

一旦您获得了正确格式的价格,只需通过字符串连接将“$”添加到您的 sum 变量即可。

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

关于javascript - 如何在 jQuery 中添加两个整数值并以 $ amount 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27494570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com