勾选时在单价上加价,不勾选时减去单价

Add price to unit price when checked, minus price when unchcked

所以我在这一栏的底部有一个 'total' 字段。

此字段上方是复选框,选中时,'total' 应通过添加该复选框的价格进行更新,未选中时,价格应被删除。

所以类似于 http://www.tepilo.com/#packages-anc

单击复选框时,以下代码会更新价格
取消点击时它什么都不做
再次点击时,它会添加到新的当前价格

    $('.col-2 input[type="checkbox"]').on('click', function() {
        var attribute_name = $(this).val();
        var attribute_price = settings.wsapo_custom[0][attribute_name].price;
        var current_price_total = $(".col-2 #update-price").text();

        var new_price = parseInt(current_price_total) + parseInt(attribute_price);

        console.log(new_price);
        $(".col-2 #update-price").text(new_price);


    });

提前致谢

这里使用 jquery 中的 onchange 或 change 函数就足够了。检查复选框是否被选中,然后相应地更改数据。

JSFIDDLE 上的演示:http://jsfiddle.net/lrojas94/t9d04oeb/

代码:

    $('input[type="checkbox"]').change(function(){
    var actual = parseInt($('p').text());        
    if($(this).is(':checked'))
           actual+= 100; 
    else
        actual-=100;
    $('p').text(actual);
});

并随时阅读有关此功能的文档:http://api.jquery.com/change/