gpt4 book ai didi

jquery - 每当我在 jQuery 中添加其他值时,如何每次刷新总值?

转载 作者:搜寻专家 更新时间:2023-10-31 08:51:47 24 4
gpt4 key购买 nike

var real_price = $('#price').text(); // getting values from total
var s1_price = $("input[name=s_sub_service]:checked").val(); // getting checked radio button value.
$('#price').text(parseInt(s1_price) + parseInt(string1)); // showing total value in price id.

我在这里添加不同的不同值并给出总值。问题是每当我将新值添加到总计中时,它也会给我旧值并添加到总计中。

最佳答案

这应该有效。

$("input").on("change keyup", function(e) {
var checkboxVal = parseInt($("input[type='radio']:checked").val(), 10);
var price = parseInt($("#price").val(), 10);
if (isNaN(price)) {
price = 0;
}
var finalPrice = price + checkboxVal;
$("#out").html(finalPrice);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" name="group1" value="5" checked>5
<input type="radio" name="group1" value="10">10
<input type="radio" name="group1" value="15">15
<input type="radio" name="group1" value="20">20
<br/>
<input type="text" id="price">
<div id="out">
</div>

关于jquery - 每当我在 jQuery 中添加其他值时,如何每次刷新总值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41220672/

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