文本框中的描述性文本多于NaN

More descriptive text than NaN on textbox

本文关键字:本多 NaN 文本多 描述性 文本      更新时间:2024-02-16

我有一个带有选择框的表格

假设您从Convert from和Convert To中选择一个选项,而不是在结果文本框中获得NaN,我想要一个更具描述性的文本,比如

"请在左侧的输入栏中输入一个数字"

如果有人在输入字段中输入数字以外的任何内容,也会发生同样的情况。我希望在文本字段中显示相同的文本。

我不知道怎么做?

在更改文本之前运行if语句

if (math is NaN) //change text
else //number
if(input is a number){
   display the result
}
else{
   display your custom message both in result and input textbox
}

您甚至可以在输入文本框的下方或左侧放置一个空的division标记,并在出现错误时使用在div中显示您的消息

div.innerHTML(Your message); 

或者在用户输入一些值并离开输入文本框后立即进行验证。

    if (isNaN(document.querySelectorAll('.result')[0].innerHTML))
{
document.querySelectorAll('.result')[0].innerHTML = "Please enter a number in the input field and choose all the select fields from the left hand side ... " 
}