Javascript 实时更新总数

Javascript 实时更新总数,javascript,html,jquery,css,Javascript,Html,Jquery,Css,正如您在图中看到的,每次我单击+或-时,总数都会更新 这是我在图像框中的html代码: Cialda a triangolo“第六佩齐联合会” 这是我的jQuery: 函数calcPrice(){ var价格=0; 变量$panna=$('#panna')。是(':checked'); 变量$radio1=$('#radio1')。是(':checked'); 变量$radio2=$('#radio2')。是(':checked'); 变量$radio3=$('#radio3')。是('

正如您在图中看到的,每次我单击+或-时,总数都会更新

这是我在图像框中的html代码:


Cialda a triangolo“第六佩齐联合会”
这是我的jQuery:

函数calcPrice(){
var价格=0;
变量$panna=$('#panna')。是(':checked');
变量$radio1=$('#radio1')。是(':checked');
变量$radio2=$('#radio2')。是(':checked');
变量$radio3=$('#radio3')。是(':checked');
变量$radio4=$('#radio4')。是(':checked');
var$cialda1=$(“输入[name=quantita_cialda_triangolo]”)val();
var$valcialda1=3;
$(“输入[名称=比索][数据价格]:选中”)。每个(函数(i,el){
价格+=+$(el).数据(“价格”);
});
如果($panna&&$radio1){
价格=3+价格;
}
如果($panna&$radio2){
价格=5+价格;
}
如果($panna&$radio3){
价格=5+价格;
}
如果($panna&$radio4){
价格=5+价格;
}
函数乘法(a,b){
返回a*b;
}
var$m1=乘法($cialda1,$valcialda1);
价格=$m1+价格;
$(“#总计”)。文本(价格);
}
$(“input[type=radio]”)。打开(“change”,calcPrice);
$(“输入[type=checkbox]”)。打开(“更改”,calcPrice);
calcPrice();
+/的代码-

$('.count triangolo').prop('disabled',true);
$(文档).on('click','plus triangiolo',function(){
$('.count triangolo').val(parseInt($('.count triangolo').val())+1);
});
$(文档).on('单击','。减去三角形',函数(){
$('.count triangiolo').val(parseInt($('.count triangiolo').val())-1);
if($('.count triangolo').val()==0){
$('.count triangolo').val(0);
}
});
jQuery与其他输入(radio、check)完美配合,基本上每当发生什么事情时,总数都会更新,但我不能通过单击+或-,实时更新它


提前感谢。

只需在('click',calcPrice')上添加
$('减号triangolo,.plus triangolo')。。。或者,如果存在此单击事件,则在末尾添加
calcPrice()
@skobaljic我已经尝试过该解决方案。计数器从0开始,如果我单击+它将变为1,但总数保持在0。如果我再次添加总更新,但不正确。您尚未发布您的正负Javascript事件。。。你如何处理它们?如果以后添加了这些按钮,则可以使用事件委派作为“$('body')。在('click','上。减去triangiolo、.plus triangiolo',calcPrice)@skobaljic我在这两个事件中添加了它,
$(document)(和减号),只需在末尾添加
calcPrice()-还要确保calcPrice函数在全局范围内。只需在('click',calcPrice')上添加
$('.减去triangolo,.plus triangolo')。。。或者,如果存在此单击事件,则在末尾添加
calcPrice()
@skobaljic我已经尝试过该解决方案。计数器从0开始,如果我单击+它将变为1,但总数保持在0。如果我再次添加总更新,但不正确。您尚未发布您的正负Javascript事件。。。你如何处理它们?如果以后添加了这些按钮,则可以使用事件委派作为“$('body')。在('click','上。减去triangiolo、.plus triangiolo',calcPrice)@skobaljic我在这两个事件中添加了它,
$(document)(和减号),只需在末尾添加
calcPrice()-还要确保calcPrice函数在全局范围内。