html表中输入字段的总和

时间:2015-11-10 17:45:37

标签: jquery

我有一个html表,在我表的每一行都有输入fiels。我想计算每一行的总和。 我的代码仅适用于第一行。

感谢您的帮助

    $(document).ready(function() {
    //this calculates values automatically 
    somme();
    $("#AutrePayantAvant, #AutrePayantApres, CPMAvant, CPMApres, EmulationAvant,EmulationApres, MoteurderechercheAvant, MoteurderechercheApres, MyCoregAvant, MyCoregApres, NonpayantAvant, NonpayantApres, PayantWeeDoItAvant, PayantWeeDoItApres, QualificationAvant, QualificationApres").on("keydown keyup", function() {
        somme();
    });
});
function somme() {
            var AutrePayantAvant = document.getElementById('AutrePayantAvant').value;
            var AutrePayantApres = document.getElementById('AutrePayantApres').value;
            var result1 = parseInt(AutrePayantAvant) + parseInt(AutrePayantApres);
            /*---*/
            var CPMAvant = document.getElementById('CPMAvant').value;
            var CPMApres = document.getElementById('CPMApres').value;
            var result2 = parseInt(CPMAvant) + parseInt(CPMApres);
            /*--*/
            var EmulationAvant = document.getElementById('EmulationAvant').value;
            var EmulationApres = document.getElementById('EmulationApres').value;
            var result3 = parseInt(EmulationAvant) + parseInt(EmulationApres);
            /*--*/
            var MoteurderechercheAvant = document.getElementById('MoteurderechercheAvant').value;
            var MoteurderechercheApres = document.getElementById('MoteurderechercheApres').value;
            var result4 = parseInt(MoteurderechercheAvant) + parseInt(MoteurderechercheApres);
            /*---*/
            var MyCoregAvant = document.getElementById('MyCoregAvant').value;
            var MyCoregApres = document.getElementById('MyCoregApres').value;
            var result5 = parseInt(MyCoregAvant) + parseInt(MyCoregApres);
            /*---*/
            var NonpayantAvant = document.getElementById('NonpayantAvant').value;
            var NonpayantApres = document.getElementById('NonpayantApres').value;
            var result6 = parseInt(NonpayantAvant) + parseInt(NonpayantApres);
            /*---*/
            var PayantWeeDoItAvant = document.getElementById('PayantWeeDoItAvant').value;
            var PayantWeeDoItApres = document.getElementById('PayantWeeDoItApres').value;
            var result7 = parseInt(PayantWeeDoItAvant) + parseInt(PayantWeeDoItApres);
            /*---*/
            var QualificationAvant = document.getElementById('QualificationAvant').value;
            var QualificationApres = document.getElementById('QualificationApres').value;
            var result8 = parseInt(QualificationAvant) + parseInt(QualificationApres);

            if (!isNaN(result1)) {
                document.getElementById('ResAutrePayant').value = result1;
            }
                if (!isNaN(result2) && !isNaN(result1) ) {
                document.getElementById('ResCPM').value = result2;
                }
                if (!isNaN(result3)) {
                document.getElementById('ResEmulation').value = result3;
                }
                if (!isNaN(result4)) {
                document.getElementById('ResMoteurderecherche').value = result4;
                }
                if (!isNaN(result5)) {
                document.getElementById('ResMyCoreg').value = result5;
                }
                if (!isNaN(result6)) {
                document.getElementById('ResNonpayant').value = result6;
                }
                if (!isNaN(result7)) {
                document.getElementById('ResPayantWeeDoIt').value = result7;
                }
                if (!isNaN(result8)) {
                document.getElementById('ResQualification').value = result8;

            }
        }

0 个答案:

没有答案