Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
576 views
in Technique[技术] by (71.8m points)

checkbox - calculate total value checkboxes jquery

http://jsfiddle.net/kcd6r/

how do i calculate total rel value? if one checkbox selected the total will be updated automatically

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Hope this helps:

$("input[type=checkbox]").change(function(){
  recalculate();
});


function recalculate(){
    var sum = 0;

    $("input[type=checkbox]:checked").each(function(){
      sum += parseInt($(this).attr("rel"));
    });

    alert(sum);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...