javascript add checkbox-checked values

前端 未结 3 842
执念已碎
执念已碎 2021-01-22 03:05

I have a checkbox section that users can select to add features. I need each input\'s value to add to a sum to be presented in the #payment-total and #payment-rebill section. Es

3条回答
  •  被撕碎了的回忆
    2021-01-22 03:20

    total1 = document.getElementById('payment-rebill');
    

    Gets the id 'payment-billed' and assigns a copy of it to var total1. Then

    total1.innerHTML = parseFloat(total1.innerHTML) + add
    

    Only changes the innerHTML of the COPY that you made a second ago. Try jQuery:

    total1 = parseFloat(total1.innerHTML) + add
    $("#payment-rebill").innerHTML(total1);
    

    This way you do the calculations on the copy, then replace the original innerHTML with the copy's innerHTML.

    EDIT -- To make it more clear, your original code was only changing the local copy total1. There wasn't any code to update the original #payment-rebill element.

提交回复
热议问题