总价我想从选择列表+复选框计算总价计算从复选框+选择列表
这个代码表示从列表中选择元素的价格“电视”:
<script type="text/javascript">
$(document).ready(function() {
var cheap = false;
$('#tvs').change(function() {
var price = parseFloat($('.total').data('base-price')) || 0;
$('#tvs').each(function (i, el) {
price += parseFloat($('option:selected', el).data(cheap ? 'cheap' : 'price'));
console.log('x', price)
$('.total').val(price.toFixed(2) + '' + '$');
});
});
});
</script>
<input placeholder="0.00$" style=" width: 65px; border: 0px;" class="total" data-base-price="0" readOnly>
并显示选中的复选框的价格验证码:
<script type="text/javascript">
function update_amounts_modal() {
var sum = 0.0;
$('form').each(function() {
var qty = $(this).find('.qty').val();
var price = $(this).find('.price').val();
var isChecked = $(this).find('.idRow').prop("checked");
if (isChecked){
qty = parseInt(qty, 10) || 0;
price = parseFloat(price) || 0;
var amount = (qty * price);
sum += amount;
}
});
$('.total-modal').text(sum.toFixed(2) + ' ' + '$');
$().ready(function() {
update_amounts_modal();
$('form .qty, form .idRow').change(function() {
update_amounts_modal();
});
});
</script>
<div id="subusers" class="total-modal">0.00 $</div>
我在这里没有看到问题。有什么我们可以帮你做的吗? – MakPo
是的,我想要一个代码来计算这两个总计 – musa94