javascript - 即使满足条件,for循环也不会执行
问题描述
该代码应该绘制从我制作的几个字段中获取值的图形,一切正常,直到它进入 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));
}
}
解决方案
推荐阅读
- image - 从 URL 获取图像 - Power Apps
- magento2 - 用于保存配置 magento 2 的插件
- python - HTML页面图标未显示在Django中
- c - void 指针,并重新转换为所需的类型
- pine-script - pine 脚本 - ADX 指示修改
- reference - 防止 Visual Studio 2017 将近 100 个不必要的系统 dll 复制到 dll 项目的输出文件夹
- ios - 应用程序崩溃并调用 [ServicesDaemonManager] interruptHandler。-[FontServicesDaemonManager 连接]_block_invoke
- javascript - 如何使用 Selenium 和 Python 从由空格分隔的文本节点获取文本
- fonts - 无法嵌入字体时的位图文本
- javascript - .map() 显示来自 api 的数据的问题