我正在尝试使用“添加到购物车”按钮将价格更改为下方,将有多个产品,他们都需要加总价格。我已经写出了jQuery,但是有一些问题针对要放入购物车的价格。
任何帮助将不胜感激!
产品的HTML:
var price = 0;
$('add-to-cart').click(function(){
$(this).toggleClass('highlight');
if($(this).hasClass('highlight')){
price += parseInt($(this).parent().child().find('.price > span').text());
}else{
price -= parseInt($(this).parent().find('.price > span').text());
}
$('.shopping-cart > span').text(price);
});
jQuery的:
public class BaseActivity extends Activity implements BackgroundServiceCallback{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BaseActivity.this.startBackgroundService();
}
@Override
public void onBackgroundServiceCallback() {
// no concrete implementation (will be implemented in child_a)
}
public void startBackgroundService() {
// configure and start the service here
}
}
codepen将提供所有细节和清晰视图。
谢天谢地!
答案 0 :(得分:0)
$('.hamburger').click(function() {
$('.nav-menu').toggleClass("nav-show");
$('.hamburger').toggleClass("hamburger-click");
});
var price = 0;
$('.add-to-cart').click(function(){
$(this).toggleClass('highlight');
if($(this).hasClass('highlight')){
price += parseInt($(this).parent().find('.price > span').text());
}else{
price -= parseInt($(this).parent().find('.price > span').text());
}
$('.shopping-cart > span').text(price);
});
$('add-to-cart')
缺少类选择器(。)
$('.add-to-cart')
和
price += parseInt($(this).parent().child().find('.price > span').text());
需要删除子()
price += parseInt($(this).parent().find('.price > span').text());