javascript - isNan 函数使下一行代码不起作用

标签 javascript html

所以,这是我的 jsfiddle:

https://jsfiddle.net/therealnemis/dxrdo9km/87/

正如你在heron()中看到的,我有三行代码,第三行是更改其中包含“answer”的标签,即我的HTML中的h3标签。如果我将标签放在第二行,那么当我按下标有“Something”的按钮时,代码将执行:

    var answer = squareRoot(15);

  //If the answer is NaN, this is due to the fact that the triangle is not possible.
 document.getElementById("answer").innerHTML = squareRoot(15);
 result = checkIfRealTriangle(answer);

当我按下标有 Something 的按钮时,这会起作用,因为 document.GetElementById 位于 checkIfRealTriangle 之前,其中包含 isNaN 函数。如果我将 getelementbyID 移至 isNaN 函数下方,那么当我按下标记为 Something 的按钮时,什么也不会发生。如果我摆脱 isNaN,一切都会正常。

最佳答案

您需要定义 checkIfRealTriangle(answer) 函数中的“区域”变量。如果您查看控制台,您会看到错误。

关于javascript - isNan 函数使下一行代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49782109/

相关文章:

javascript - 如何读取跨域图片自带的cookie值?

javascript - 访问对象数组中具有未知属性名称的生成属性

android - 当虚拟键盘出现时,三星 Android 上的 Html 输入失去焦点

javascript - 单击更改元素的背景图像

javascript - 如何用 % 突出显示每隔一行?

javascript - CSS/JQuery 菜单在 Firefox 中无法正常运行

javascript - 使用 LESS 检测浏览器版本

javascript - 反序列化后重新应用 JS Prototype 函数

javascript - jquery-如何检测 child 的ID?

javascript - 客户端 HTML 表单验证