gpt4 book ai didi

javascript - isNAN 没有评估

转载 作者:行者123 更新时间:2023-11-30 08:43:40 26 4
gpt4 key购买 nike

新手在这里学习

我正在尝试检查输入到我的表单中的数据,如果输入到第二个或第三个输入中的数据不是数字(即按字母顺序排列),则向用户显示信息不是数字的通知。我正在使用“isNaN”函数来执行此操作,但根据我在 Google、Stack 和其他地方阅读的内容,它并没有像我希望的那样工作。我已经尝试过“isNaN”和“!isNaN”,但都没有触发我的脚本中希望发生的事件。

这是我正在尝试的 JavaScript: if(empty(thisForm.epiName,"剧集名称留空。请输入剧集名称提交,以便我们大胆地去检查您的结果!")){return false;}

        if(empty(thisForm.rsTot,"Red shirt total left blank. Please enter the total estimated number of Starfleet officers wearing red shirts to appear in this episode so we can boldly go and check your results!")){return false;}

if(empty(thisForm.reRemaining,"Red shirts surviving left blank. Please enter the number of Starfleet officers to survive this episode so we can boldly go and check your results!")){return false;}

if(isNaN(thisForm.rsTot,"Info entered is not a number, we can not boldly check your result!")){return false;}

if(isNaN(thisForm.reRemainder,"Info entered is not a number, we can not boldly check your result!")){return false;}



return true;//if all is passed, submit!

网站网址:http://zephir.seattlecentral.edu/~jstein11/itc250/z14/_sbx031_OOPform/sbx031b_OOPform.php

最佳答案

isNaN 只接受 1 个参数。此外,您应该知道在检查之前参数被强制转换为数字。

为避免意外结果,最好先检查它是否为数字。

function safeIsNaN(num) {
if (typeof num !== "number") {
return true; //this is Not-a-Number
}
return isNaN(num);
}

关于javascript - isNAN 没有评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23937354/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com