jQuery checkbox and select - sum the values and add in var

前端 未结 6 1113
礼貌的吻别
礼貌的吻别 2020-12-17 07:10

The explanation is below the code:

The code for HTML is :

Add-ons

6条回答
  •  萌比男神i
    2020-12-17 07:36

    Try this

    $("select").change(function() {
        $('input[name="ch1"]').change(); // trigger change to recalculate
    });
    $('input[name="ch1"]').change(function() {
        var singleValues = 0;
        $('input[name="ch1"]:checked').each(function() { // loop through checked inputs
            singleValues = +this.value + singleValues;
        });
        singleValues += (+$('#more').val().replace('QR', '').trim());  // add drop down to checked inputs
        $("#usertotal").text(singleValues);
    });​
    

    http://jsfiddle.net/wirey00/5s8qr/

提交回复
热议问题