Any way to simplify this code?

前端 未结 4 1996
悲哀的现实
悲哀的现实 2020-12-20 07:38

New to javascript! This works, but I have a lot more to do, and it would be great if there was a cleaner way to do this.. open to using jquery if neccesary :)

(stack

4条回答
  •  误落风尘
    2020-12-20 08:37

    I'd do it something like this:

    function apply() {
        var backers = 0;
        for (var i = 1; i < 20; ++i) {
            backers +=
                parseInt(document.getElementById("backer-prediction-" + i).value);
        }
        document.getElementById("backer-prediction-answer").value = backers;
    }
    

提交回复
热议问题