即使满足条件,for循环也不会执行

时间:2020-02-12 12:14:03

标签: javascript loops for-loop

该代码应该绘制图形,并从我创建的几个字段中获取值,一切正常,直到进入for循环为止,由于某种原因,该循环被完全跳过,我在循环内放入了alert()看看我的命令的语法是否不正确,但是它没有发出警报,好像for循环甚至没有运行,但是因为条件为真,所以它应该运行,这将导致代码跳过吗?

   var canvas = document.getElementById("myCanvas");
        var ctx = canvas.getContext("2d");
        var dN = document.getElementsByName("dName");
        var dV = document.getElementsByName("dValue");
        var titleInput = document.getElementById("titleInput");
        var stitleInput = document.getElementById("stitleInput");



        function blek()    {

            var propRatio = 1;
            dV.forEach(ratioCalc);

            function ratioCalc(val){
                    if(propRatio > (1 / (val.value / 1000))) {
                    propRatio = (1 / (val.value / 1000)) / 100 * 70;
                    }
            }

            ctx.font = "30px 'Roboto Mono'";
            ctx.clearRect(0,0, canvas.width, canvas.height);
            ctx.fillText(titleInput.value, 10, 50);
            ctx.font = "24px 'Roboto Mono'";
            ctx.fillText(stitleInput.value, 10, 80);

            for (i = 0; i > dV.length; i++) {
                //This is problem part, the loop doesn't execute at all and there is no console output.
                ctx.fillText(dN[i].value, 10, 133 + (60 * (i+1)));
                ctx.fillRect(200, 100 + (50 * (i+1)) + 10, dV[i].value * propRatio, 50);
                ctx.fillText(dV[i].value, 20 + dV[i].value * propRatio, 133 + (50 * (i+1) + 10));

            }


        }

0 个答案:

没有答案