有单选按钮和多选选项。他们的数据价值部分有价格。例如:数据值 = "3.10"。我想做的就是这个。在屏幕上打印所选数据的总和。我希望我能告诉。
这两个选项给出不同的总价格。我想把两者加起来。
$(document).ready(function() {
var price = 10.09;
var net_fiyat=0;
$('input[type=radio]').on('click',function(){
data= $(this).data('price');
net_fiyat = (parseFloat(price) + parseFloat(data));
console.log(price,data);
console.log(net_fiyat);
$('#total').text(net_fiyat);
});
$(".ekstra").change(function(event) {
var total = 0;
$(".ekstra").select().find(":selected").each(function() {
console.log(this,price);
total += parseFloat($(this).data("price"));
});
if (total == 0) {
$('#total').html('');
} else {
var net_fiyat2 = price + total;
console.log('net2');
$('#total').html(net_fiyat2.toFixed(2));
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-md-12">
<div class="container">
<div class="row">
<div class="col-md-12 pd-40">
<select multiple data-placeholder="Ekstra Malzeme Seçin.." class="ekstra">
<option data-price="1.10">Pizza Sos</option>
<option data-price="1.10">Beyaz Peynir</option>
<option data-price="1.10">Mozarella Peyniri</option>
<option data-price="1.10">Sucuk</option>
<option data-price="1.10">Sosis</option>
</select>
</div>
</div>
</div>
</div>
<input class="radio-button" type="radio" name="radio" data-price="5.12" />
<input class="radio-button" type="radio" name="radio" data-price="6.50" />
<span class="font-size-27 font-weight-bolds ml-1" id="total">$10.09</span>
繁华开满天机
相关分类